对于一个基于ICS的应用程序,我创建了一个ListFragment,它反过来使用一个BaseAdapter实现。为了显示上下文操作栏,我启用了multichoicemodelistener()。但这里的问题是,每当我选中复选框或长按标签(两者都在baseadapter中的视图集中)时,就根本不会调用multichoicemodelistener实现。任何形式的帮助都是非常感谢,因为我是完全卡住后,尝试了许多选择!!!!
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
}
}
最佳答案
您需要使用ActionMode.Callback
。You should read through these docs,实际上使用起来相当简单。