我有一个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);
}
Run Code Online (Sandbox Code Playgroud)
编辑:这个ansewer不好 ...为什么我这样做这种奇怪的方法?因为Eclipse的智能感知不propmt"好" setOnLongClickListener的ListView(因为ListView至少有2种setOnLongClickListener方法......从一个View和第二从AdapterView类)......最简单的方法就是让你的ListFragment实现AdapterView.OnItemLongClickListener,然后onViewCreated添加代码getListView().setOnLongClickListener(this);
通过"长按",我认为你指的是上下文菜单.对于a ListFragment,您应该做的就是注册上下文菜单:
@Override
public void onActivityCreated(Bundle icicle) {
registerForContextMenu(getListView());
}
Run Code Online (Sandbox Code Playgroud)
一旦你这样做,ListFragment应该打电话onCreateContextMenu(),onContextItemSelected()当它检测到长按.
| 归档时间: |
|
| 查看次数: |
4479 次 |
| 最近记录: |