为了选择最喜欢的联系人,我将所有联系人加载到列表视图中并声明我的适配器,如下所示:
ArrayAdapter<String> cnct_List_Adapter =new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_multiple_choice,info);
为了显示结果,我使用以下代码:
try
{
SparseBooleanArray a = LvPopupContacts.getCheckedItemPositions();
String my_sel_items="";
for(int i = 0; i < LvPopupContacts.getCount() ; i++)
{
if (a.valueAt(i))
{
/*
Long val = lView.getAdapter().getItemId(a.keyAt(i));
Log.v("MyData", "index=" + val.toString()
+ "item value="+lView.getAdapter().getItem(i));
list.add(lView.getAdapter().getItemId((a.keyAt(i))));
*/
my_sel_items = my_sel_items + ","
+ (String) LvPopupContacts.getAdapter().getItem(i);
}
}
Toast.makeText(getActivity(),String.valueOf(a.size()), 0).show();
Log.v("Contacts :" ,my_sel_items);
} catch (Exception e) {
Log.v("e Error" ,e.toString());
}
现在,当我在其中使用它时,emulator
它可以工作rightly
,但是当它作为Device
回报进行测试时e Exception
Exception: java.lang.ArrayindexOutOfBoundsException length=13;index=13
请记住,我的设备有大约 220 个联系人。