问题描述
- 如何重写 ListFragment中的 LongPress
- 在我的应用程序中有一个ListFragment Activity。
我想为onItemClickedLongPress创建一个方法,当用户点击时,一个菜单就会弹出。那么在ListFragment Activity中如何重写LongPress?
能给我点指导吗?谢谢大家!
解决方案
@Overridepublic void onViewCreated(View view Bundle savedInstanceState) { super.onViewCreated(view savedInstanceState); //....... registerForContextMenu(getListView());}@Overridepublic 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);}
参照:https://github.com/lorensiuswlt/NewQuickAction
时间: 2024-09-28 02:14:53