I've implemented a listview (where each item is a buttom) and now I want to improve its efficiency by using a ViewHolder. Here is my problem, I dont know where must I override these button's OnClick methods.
This is the getView of my ArrayAdapter:
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder view;
if(convertView==null)
{
view = new ViewHolder();
LayoutInflater inflator = activity.getLayoutInflater();
convertView = inflator.inflate(R.layout.layout_opcion, null);
view.b_opcion = (Button) convertView.findViewById(R.id.boton_opcion);
**view.b_opcion.setOnClickListener(new View.OnClickListener() {...});**
convertView.setTag(view);
}
else
{
view = (ViewHolder) convertView.getTag();
}
**view.b_opcion.setOnClickListener(new View.OnClickListener() {...});**
view.b_opcion.setText(getItem(position));
return convertView;
}
}
This OnClick method must display some info about the item selected, so here is my question. Can I override this method inside
if(convertView==null) {HERE}
(in order to do that just once)? Or against that, inside this IF there must be just the lines of code which refer to inflating layouts?