Because I am using a custom listView adapter for my applicaiton, some of the default methods are overridden. The problem occurs when I call the getItem(position)
method of the adapter. Because this method is overridden, my attempt to find out the selected items are returned as null.
The custom adapter overrides the method as follows:
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
The call for getting the selected items:
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// retrieve selected items and print them out
ArrayListAdapter adapter = (ArrayListAdapter) Allprojects.this.getListAdapter();
SparseBooleanArray selected = adapter.getSelectedIds();
StringBuilder message = new StringBuilder();
for (int i = 0; i < selected.size(); i++){
if (selected.valueAt(i)) {
String selectedItem = (String) adapter.getItem(selected.keyAt(i));
message.append(selectedItem + "\n");
}
}
Toast.makeText(Allprojects.this, message.toString(), Toast.LENGTH_LONG).show();
// close action mode
mode.finish();
return false;
}
How do I now override the getItem(position) method such that I get the selected items. Please do help.