Here is My Custom ListViewAdapter
public class ListViewAdapter extends BaseAdapter{
Viewholder holder;
public ArrayList>
istesd use
holder.ckbox.setText(checkedItems[position]?"Added","Add");
and remove
holder.tvckboxText.setText(ckboxTextAdd[position]?"Added","Add"););
this because it might not support the landscape view
Problem:
When you're updating the values of array to map the status of checked or un-checked, you're not updating the TextView
, as CheckBox
's check or uncheck works out-of-box as implemented the api, but TextView
's text need to be updated.
Solution:
You need to either manually update the TextView
's text, or simply call notifyDataSetChanged()
whenever you check or uncheck the item, this will let the getView()
of Adapter called and will force to refresh the row based on updated value.
Suggestion/Improvement:
You can maintain single array of boolean only, no need to maintain the String array of Added or Add, while showing text, check if the boolean is true, set text as "Added", else "Add" like this:
holder.ckbox.setChecked(checkedItems[position]);
holder.tvckboxText.setText(checkedItems[position]?"Added":"Add");
Instead of implementing anonymous CompoundButton.OnCheckedChangeListener
, implement it to class level and set as this
, as of now you're creating multiple CompoundButton.OnCheckedChangeListener
object every time when you scroll through the list.
Where are you closing the db? It doesn't matter though, but its good to have a closing point.