我有一个ListFragment活动.
我想为onItemClickedLongPress创建一个方法,以便在用户执行此操作时.弹出一个菜单.我熟悉创建菜单.
所以,如果有人愿意,请给我进一步说明如何在ListFragment活动中设置覆盖longpress?
解决方法
编辑:此示例显示如何显示系统菜单fx之外的其他内容.从
https://github.com/lorensiuswlt/NewQuickAction开始的QuickAction
@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);