对于基于 ICS 的应用程序,我创建了一个 ListFragment,它又使用 BaseAdapter 实现。我已启用 MultiChoiceModeListener() 以显示上下文操作栏。但这里的问题是,每当我检查 CheckBox 或长按标签(两者都在 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
}
}