I would like to know if in some way it is recommended to have an adapter for each Activity .
I know what to do with an Adapter for every Activity is quiet.
Now how to make a generic Adapter , would it?
Would you be following the design patterns?
My Activity
public class CardapioPizzaria extends Activity {
ListView listViewCardapio;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cardapio_pizzaria);
this.listViewCardapio = (ListView) findViewById(R.id.listCardapio);
CardapioAdapter cardapioAdapter = new CardapioAdapter(this);
this.listViewCardapio.setAdapter(cardapioAdapter);
}
}
Adapter
public class CustomAdapter extends BaseAdapter {
private Context context;
@SuppressWarnings("unused")
private static final String TAG = CustomAdapter.class.getSimpleName();
ArrayList<DataModel> listArray;
/*Construtor*/
public CustomAdapter(Context context) {
this.context = context;
listArray = new ArrayList<DataModel>();
listArray.add(new DataModel("Bom Filé","3214 - 2435"));
listArray.add(new DataModel("Porcão","3214 - 2435"));
listArray.add(new DataModel("Palmarys","3214 - 2435"));
listArray.add(new DataModel("Fat Boy","3217 - 2452"));
listArray.add(new DataModel("Fratelli","3215 - 5010"));
listArray.add(new DataModel("Pizza Paulista","3214 - 3271"));
listArray.add(new DataModel("Fogão a Lenha","3215 - 5168"));
listArray.add(new DataModel("Alô Pizza","3214 - 4193"));
}
/**Total de elementos dentro do array */
public int getCount() {
return listArray.size();
}
/**Pegando o item da lista */
public Object getItem(int i) {
return listArray.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int index, View view, final ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.itens_lista, parent, false);
}
final DataModel dataModel = listArray.get(index);
TextView textView = (TextView) view.findViewById(R.id.nome_estabelecimento);
textView.setText(dataModel.getName());
TextView textViewTelefone = (TextView) view.findViewById(R.id.numeroTelefone);
textViewTelefone.setText("" + dataModel.getTelefone());
Button buttonLigar = (Button) view.findViewById(R.id.btn_ligar_pizza);
Button buttonVerCardapio = (Button) view.findViewById(R.id.btn_ver_cardapio_pizza);
buttonLigar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri url = Uri.parse("tel: " + dataModel.getTelefone());
Intent it = new Intent(Intent.ACTION_CALL,url);
context.startActivity(it);
}
});
buttonVerCardapio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent it = new Intent(context, CardapioPizzaria.class);
context.startActivity(it);
}
});
return view;
}
}
I did not put layouts because I did not see any need.