Не могу разобраться в каком методе что реализовывать.
Код: Выделить всё
public class MyListAdapter extends SimpleCursorAdapter {
private LayoutInflater layoutInflater;
Context context;
public MyListAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
this.context = context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tvName = (TextView)view.findViewById(R.id.name);
CheckBox checkBox = (CheckBox)view.findViewById(R.id.checkBox);
ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
tvName.setText(cursor.getString(1));
checkBox.setChecked((cursor.getInt(2) == 0 ? false:true));
if (checkBox.isChecked()) {
imageView.setImageResource(R.drawable.avatar);
} else imageView.setImageResource(R.drawable.no_avatar);
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) convertView = layoutInflater.from(context).inflate(R.layout.list_item, null);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
//TextView tvName = (TextView)convertView.findViewById(R.id.name);
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
if (checkBox.isChecked()) {
imageView.setImageResource(R.drawable.avatar);
} else imageView.setImageResource(R.drawable.no_avatar);
return convertView;
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
}
при включении чекбокс должен появиться аватар.
не получается (((