1 创建适配器
data = service.getAllDataStringArray(); ArrayAdapter<String> charaAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_checked, data); eventCharaList.setAdapter(charaAdapter); eventCharaList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); eventCharaList.refreshDrawableState();// TODO 刷新listview,否则,获取checkedItem的时候会受上次打开listview的选择影响
2 获得选择的选项
StringBuilder sb = new StringBuilder(); SparseBooleanArray positions = eventCharaList.getCheckedItemPositions(); int size = positions.size(); for(int index=0;index<size;index++){ sb.append(data[positions.keyAt(index)]+","); } Toast.makeText(getActivity(), String.valueOf(eventCharaList.getCheckedItemCount())+";"+sb, 0).show();