Here is my custom arrayadapter class, I want to change the image resource of a button in each row when I click ont it, it works but an other button in an other row also changes. thanks for your help !
public class Coursadapter extends ArrayAdapter<String> {
Context context;
int layoutResourceId;
ArrayList<String> data = null;
WeatherHolder holder;
public Coursadapter(Context context, int layoutResourceId,
ArrayList<String> data) {
// super(context, layoutResourceId, data, coeff);
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, null);
holder = new WeatherHolder();
holder.name = (TextView) row.findViewById(R.id.item_cours_name);
holder.b = (ImageButton) row.findViewById(R.id.button);
holder.b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WeatherHolder w = (WeatherHolder) v.getTag();
w.b.setImageResource(R.drawable.butgreen);
}
});
row.setTag(holder);
} else {
holder = (WeatherHolder) row.getTag();
}
holder.b.setTag(holder);
String name1 = data.get(position);
holder.name.setText(name1);
return row;
}
static class WeatherHolder {
TextView name;
ImageButton b;
}
}