Android: MultiChoiceModeListener not called inside ListFragment

For an ICS based application, I created a ListFragment, which in turn uses the BaseAdapter implementation. I have included MultiChoiceModeListener () to display a contextual action bar. But the problem here is that whenever I check the CheckBox or press Label for a long time (both are in the view set in the BaseAdapter), the implementation of MultiChoiceModeListener is not called at all. Any help is much appreciated as I am completely stuck after many options!

public class ActivitiesFragment extends ListFragment {

public void onActivityCreated(Bundle savedInstanceState) {
    Log.d(TAG, "Entering onActivityCreated()");
    super.onActivityCreated(savedInstanceState);

    this.setAdapter();
    this.setHasOptionsMenu(true);
}

private void setAdapter() {

    HashMap<String, String> activities = DBAdapter
            .getInstance(this.context).getActivities();
    setListAdapter(new ActivitiesList(Util.sortByComparator(activities)));

    ListView listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiSelectionListener());

}

private class ActivitiesList extends BaseAdapter {
    // Other functions declared
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ActivityView view = null;
        String activityName = this.activityList.get(position);
        String colour = this.activities.get(activityName);

        if (convertView == null) {
            // ActivityView is a LinearLayout with CheckBox, Label and a Button
            view = new ActivityView(context, activityName, colour);

        } else {
            view = (ActivityView) convertView;
            view.setActivityName(activityName);
        }
        return view;
    }
}

private class MultiSelectionListener implements MultiChoiceModeListener {
    // implementation
}

}
+3
source share
4 answers

ActionMode.Callback. , .

0

, onLongClickListener. , , ViewHolder, MultiChoiceListener .

0

, , , ListView, CheckBox, MultiChoiceModeListener. CustomChoiceList ( Android Studio FileImport Sample), , View ListView Checkable. CustomChoiceList

ListView SelectionMode, "" . , :

android.R.layout.simple_list_item_single_choice android.R.layout.simple_list_item_multiple_choice.

. Checkable.

, docs Checkable. ,

, setItemChecked().

You do not need to worry about ActionMode.Callback, because it is processedMultipleChoiceModeListener

0
source

There may be a bug in your implementation of MultiChoiceModeListener. This works great for me.

-3
source

All Articles