大家好,我一直在寻找获取自定义列表视图详细信息的方法。例如,我有listview,其中将嵌入包含复选框的自定义视图。我需要做的就是点击按钮找到复选框的状态。在这种情况下还需要知道如何使用getAdapter方法..
先谢谢..
编辑#1
class MyEthnicityAdapter extends BaseAdapter {
Context rContext;
private LayoutInflater rInflater;
View view;
public MyEthnicityAdapter(Context c) {
rInflater = LayoutInflater.from(c);
rContext = c;
}
@Override
public int getCount() {
/* return Library.s.size(); */
return getResources().getStringArray(R.array.ethnicity).length;
}
@Override
public Object getItem(int position) {
// return null;
System.out.println("My view l;st size is===> " + viewList.size());
//return viewList.get(position);
return view;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
convertView = rInflater.inflate(R.layout.custom_multi_select, null);
EthinicityDataClass mydat = new EthinicityDataClass();
mydat.ethinicitycheck = (CheckBox) convertView
.findViewById(R.id.ethnicity_check);
mydat.ethinicitycheck.setText(getResources().getStringArray(
R.array.ethnicity)[position]);
view=convertView;
return convertView;
}
class EthinicityDataClass {
CheckBox ethinicitycheck;
}
}
然后像这样设置适配器。 ethnicityListview = (ListView) findViewById(R.id.ethnicityListview);
ethnicityListview.setAdapter(new MyEthnicityAdapter(this));
答案 0 :(得分:0)
如果你这样做:
ethnicityListview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
你可以使用
ethnicityListview.isItemChecked(position);
获取getView方法中指定项的checked状态并对其中的值做出反应(如果选中则检查项,如果未选中则取消选中)。