1

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.

4

1 回答 1

3

由于您使用的是 BaseAdapter,因此您必须在其中包含项目的列表(或其他一些集合),对吗?只需使用

return list.get(position);
于 2013-09-05T15:41:28.623 回答