嗨,我正在使用多项选择列表,谁能告诉我应该如何在任何按钮单击事件中选择所有项目,或者如何在按钮单击事件中取消选择所有项目
我的代码在这里
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_list);
findViewsById();
PhoneContacts pc = new PhoneContacts(ContactList.this);
pc.readContacts();
for (int i = 0; i < pc.allPhoneNumbers.size(); i++) {
_allNumberAndNameMergeList.add(pc.allContactName.get(i) + "\n"
+ pc.allPhoneNumbers.get(i));
}
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
_allNumberAndNameMergeList);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(adapter);
button.setOnClickListener(this);
}
private void findViewsById() {
listView = (ListView) findViewById(R.id.list);
button = (Button) findViewById(R.id.testbutton);
}
public void onClick(View v) {
SparseBooleanArray checked = listView.getCheckedItemPositions();
ArrayList<String> selectedItems = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems.add(adapter.getItem(position));
}
String[] outputStrArr = new String[selectedItems.size()];
for (int i = 0; i < selectedItems.size(); i++) {
outputStrArr[i] = selectedItems.get(i);
}
}
}
嗨,我正在使用多项选择列表,谁能告诉我应该如何在任何按钮单击事件中选择所有项目,或者如何在按钮单击事件中取消选择所有项目