Task: foliage from image, text and checkbox. Data from DB. If the checkbox is on, the picture changes to another. + save, delete and edit records.

At the moment I have this.

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); final CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkBox); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ checkBox.isChecked() = true; } else checkBox.isChecked() = false; } }); //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(); } 

It looks like this. // text is not displayed. by clicking the checkbox the pictures do not change. enter image description here

I assume that the adapter is incorrectly implemented. Plus, I don’t understand when, how and where to invoke a display update. I would be glad if you tell me.

  • Comments are not intended for extended discussion; conversation moved to chat . - PashaPash

0