android – 如何在ListFragment中覆盖LongPress?

我有一个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没有为Lis​​tView提供“好”的setonLongClickListener(因为ListView至少有2个setonLongClickListener方法……一个来自View,另一个来自AdapterView类)…最简单的方法是让你的ListFragment实现AdapterView.OnItemLongClickListener然后进入onViewCreated添加代码getListView().setonLongClickListener(this);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...