如何替代长preSS在ListFragment? [英] How to Override LongPress in ListFragment?

查看:147
本文介绍了如何替代长preSS在ListFragment?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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);

这篇关于如何替代长preSS在ListFragment?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆