gpt4 book ai didi

安卓 : MultiChoiceModeListener not invoked inside ListFragment

转载 作者:太空狗 更新时间:2023-10-29 15:29:01 24 4
gpt4 key购买 nike

对于基于 ICS 的应用程序,我创建了一个 ListFragment,它又使用 BaseAdapter 实现。我启用了 MultiChoiceModeListener() 以显示上下文操作栏。但这里的问题是,每当我检查 CheckBox 或长按 Label(两者都在 BaseAdapter 的 View 集中)时,根本不会调用 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.CallbackYou should read through these docs ,它实际上使用起来非常简单。

关于安卓 : MultiChoiceModeListener not invoked inside ListFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10592902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com