我有一个列表和ArrayAdapter可以显示它(基本上作为CheckBox的列表)。 MyObejct只有几个字段,其中一个是启用布尔值的。ListView与ArrayAdapter:点击复选框时的更新模型
我该怎么做,点击CheckBox会改变相应的模型?喜欢的东西:
public class MyObjectAdapter extends ArrayAdapter<MyObject>{
private List<MyObject> items;
public MyObjectAdapter(Context context, int textViewResourceId, List<MyObject> objects) {
super(context, textViewResourceId, objects);
this.items = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.myobject_checkbox, null);
}
MyObject myobject = items.get(position);
if (myobject!=null){
//checkbox
CheckBox cbEnabled = (CheckBox) v.findViewById(R.id.enabled);
if(cbEnabled != null){
cbEnabled.setChecked(myobject.isEnabled());
cbEnabled.setText(myobject.getName());
cbEnabled.setTag(position);
cbEnabled.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//how change model. E.g. myobject.setEnabled(((CheckBox) v).isChecked())
}
});
}
}
return v;
}
}
你能在这里发布更多的代码,即您的Adapte R' – 2011-04-24 12:03:50