作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 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/
我是一名优秀的程序员,十分优秀!