如何替代长preSS在ListFragment?preSS、ListFragment

2023-09-05 07:12:16 作者:正在缓冲……

我有一个ListFragment活动。

I have a ListFragment Activity.

我想要创建onItemClickedLong preSS的方法,从而当用户执行此操作。菜单弹出。我熟悉创建菜单。

I want to create a method for onItemClickedLongPress, so that when the user does this. a menu pops up. I am familiar with creating the menu.

所以,如果有人会请给我如何设置覆盖长preSS在ListFragment活动进一步的说明?

So if some one would please, give me further instructions on how to set Override the longpress in a ListFragment activity?

推荐答案

编辑:此示例演示如何显示的东西以外的其他系统菜单FX。 QuickAction从 https://github.com/lorensiuswlt/NewQuickAction

edit: this sample shows how to show something other then system menu fx. QuickAction from 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);
}

编辑: 这ansewer不好 ...为什么我这样做这样奇怪的方法?因为Eclipse的智能感知不propmt好 setOnLongClickListener 的ListView (因为的ListView 至少2 setOnLongClickListener 方法......一个来自查看和第二从适配器视图班)......最简单的方法就是让你的 ListFragment 实施 AdapterView.OnItemLongClickListener 然后在 onViewCreated 添加code getListView()setOnLongClickListener(本);

This ansewer is not good ... why i did this such strange method? because eclipse intellisense did not propmt "good" setOnLongClickListener for ListView (since ListView has at least 2 setOnLongClickListener methods ... one from View and second from AdapterView class) ... the easiest way is let your ListFragment implement AdapterView.OnItemLongClickListener and then in onViewCreated add code getListView().setOnLongClickListener(this);