如何使用复选框在我的列表视图中获取所选项目,我搜索此问题的答案,但没有什么足够清楚让我理解
这是我的列表视图
public void laptopTab() {
List<String> listDisplay = new ArrayList<String>();
for (int counter = 0 ; counter<laptopFilter.length;counter ++) {
listDisplay.add(laptopFilter[counter]);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.filter_listview,
R.id.filter_name,listDisplay);
laptopLV = (ListView) findViewById(R.id.laptopLV);
laptopLV .setAdapter(adapter);
laptopLV.setOnItemClickListener(this);
}
这是我的 onItemClickListener 代码
public void onItemClick(AdapterView<?> arg0, View v, int position ,
long id) {
// TODO Auto-generated method stub
if (v != null) {
cb = (CheckBox)v.findViewById( R.id.cb );
cb.setChecked(!cb.isChecked());
}
switch (th.getCurrentTab()) {
case 0:
if(cb.isChecked()){
th.getTabWidget().getChildTabViewAt(1).setEnabled(false);
th.getTabWidget().getChildTabViewAt(2).setEnabled(false);
selectedFromLaptopList.add(laptopLV.getItemAtPosition(position).toString());
}
else {
th.getTabWidget().getChildTabViewAt(1).setEnabled(true);
th.getTabWidget().getChildTabViewAt(2).setEnabled(true);
}
break;
case 1:
if(cb.isChecked()){
th.getTabWidget().getChildTabViewAt(0).setEnabled(false);
th.getTabWidget().getChildTabViewAt(2).setEnabled(false);
selectedFromMp3List.add(mp3LV.getItemAtPosition(position).toString());
} else {
th.getTabWidget().getChildTabViewAt(0).setEnabled(true);
th.getTabWidget().getChildTabViewAt(2).setEnabled(true);
}
break;
case 2:
if(cb.isChecked()){
th.getTabWidget().getChildTabViewAt(0).setEnabled(false);
th.getTabWidget().getChildTabViewAt(1).setEnabled(false);
selectedFromMobileList.add(mobileLV.getItemAtPosition(position).toString());
} else {
th.getTabWidget().getChildTabViewAt(0).setEnabled(true);
th.getTabWidget().getChildTabViewAt(1).setEnabled(true);
}
default:
break;
}
}
我在选项卡主机中有一个列表视图,所以如果在当前选项卡上选择了一个复选框,我只需要禁用另一个选项卡
我有一个按钮。我想知道在列表视图中选择的所有项目
请帮助我,并提前感谢