I hope to use lv.getCheckedItemIds().length to get the sum of selected items. It seems that ArrayAdapter doesn't support getCheckedItemIds(), right?
private void InitListView(int pos) {
List<String> msgList = getSMS(pos);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, msgList);
lv.setAdapter(adapter2);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
SetSelectedAndTotal();
}
});
}
private void SetSelectedAndTotal(){
selectedAndTotal.setText(lv.getCheckedItemIds().length+ "/"
+ lv.getCount());
}
public List<String> getSMS(int pos) {
List<String> sms = new ArrayList<String>();
Uri uriSMSURI = Uri.parse(valueList.get(pos));
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,
null);
while (cur.moveToNext()) {
String address = cur.getString(cur.getColumnIndex("address"));
String body = cur.getString(cur.getColumnIndexOrThrow("body"));
sms.add("Number: " + address + " .Message: " + body);
}
return sms;
}