gpt4 book ai didi

android - 如何在 ListFragment 中覆盖 LongPress?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:33:33 25 4
gpt4 key购买 nike

我有一个 ListFragment Activity 。

我想为 onItemClickedLongPress 创建一个方法,以便当用户执行此操作时。弹出一个菜单。我熟悉创建菜单。

因此,如果有人愿意,请给我进一步的说明,说明如何在 ListFragment Activity 中设置覆盖长按?

最佳答案

编辑:此示例展示了如何显示系统菜单 fx 以外的内容。来自 https://github.com/lorensiuswlt/NewQuickAction 的快速操作

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//.......
registerForContextMenu(getListView());
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo amenuInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
Object item = getListAdapter().getItem(amenuInfo.position);
//item could be Cursor/String/YourObject it depends on Adapter
//show popup fx. QuickAction from https://github.com/lorensiuswlt/NewQuickAction
QuickAction qa = new QuickAction(getActivity());
qa.setAnimStyle(QuickAction.ANIM_AUTO);
qa.show(amenuInfo.targetView);
}

编辑:这个答案不好 ...为什么我要用这种奇怪的方法?因为 Eclipse intellisense 没有为 ListView 提示“好”setOnLongClickListener(因为 ListView 至少有 2 个 setOnLongClickListener 方法。 .. 一个来自 View,第二个来自 AdapterView 类)...最简单的方法是让您的 ListFragment 实现 AdapterView.OnItemLongClickListener 然后在 onViewCreated 添加代码 getListView().setOnLongClickListener(this);

关于android - 如何在 ListFragment 中覆盖 LongPress?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7419012/

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