React on Checkbox Click in Cutsom ListView
I'm short before failure, although I believe the solution of my problem isn't that difficult.
I have a ListView
that is de-/serializing an ArrayList
of SettingItems
. Each row in this view contains a two textview
s and one Checkbox
. The checkbox state should consider if this item will be observed or not. For the listView code you can check my previous question:
The particular rows are created in my CustomSettingsAdapter, which is extending a BaseAdapter. Therefore it contains an ArrayList of the SettingItems.
private static ArrayList<SettingItem> settingsArrayList;
private LayoutInflater mInflater;
public CustomSettingsAdapter(Context context, ArrayList<SettingItem> sitems)
{
settingsAr开发者_StackOverflow中文版rayList = sitems;
mInflater = LayoutInflater.from(context);
}
public int getCount()
{
return settingsArrayList.size();
}
public Object getItem(int position)
{
return settingsArrayList.get(position);
}
public ArrayList<SettingItem> getItemList()
{
return settingsArrayList;
}
public long getItemId(int position)
{
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.settings_item, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.setting_name);
holder.details = (TextView) convertView.findViewById(R.id.setting_detail);
holder.cb = (CheckBox) convertView.findViewById(R.id.check);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.txtName.setText(settingsArrayList.get(position).getName());
holder.details.setText(settingsArrayList.get(position).getPath());
holder.cb.setChecked(settingsArrayList.get(position).getState());
holder.cb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
return convertView;
My thinking was just to change the ArrayList in the adapter and then give it to Activity, where it can be matched with the original list, which can afterwards normally be serialized. But i don't get it to work, with my knowledge and the things i found in the web. Much thanks in advance for helping me! Best Regards Tobi
edit:the onCheckedChangeListener:
holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
settingsArrayList.get(position).setState(isChecked);
notifyDataSetChanged();
}
});
tried it also with cd.setID and received the actual position for the ArrayList with cb.getID, but it returns with the same issue.
Try this:
holder.checkBoxListView
.setOnCheckedChangeListener(new android.widget.CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
//code for making the listItem invisible.
}
});
精彩评论