I have an array string that i used in my Fragment
,and i show the array string items with setListAdapter
in my list:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] array = getResources().getStringArray(R.array.examlearray);
final ArrayList<String> str = new ArrayList<String>(Arrays.asList(array));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, str );
setListAdapter(arrayAdapter);
final ListView listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {...
and under my onActionItemClicked
i want to implement my deleteSelectedItem() method,that delete selected list items,and this my code,but it didn't remove selected item,it is just remove from first of list,and when i select all the items and press remove,the app crash!what should do?,Any help would be appreciated! Thanks!
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Respond to clicks on the actions in the CAB
switch (item.getItemId()) {
case R.id.delete:
// deleteSelectedItems();
Log.i(TAG, "deleteSelectedEntries");
SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
for(int i=0;i<checkedItems.size();++i)
{ if(checkedItems.valueAt(i))
str.remove(i);
}
arrayAdapter.notifyDataSetChanged();