在我的应用程序中有一个ListFragment Activity。
我想为onItemClickedLongPress创建一个方法,当用户点击时,一个菜单就会弹出。
那么在ListFragment Activity中如何重写LongPress?
能给我点指导吗?谢谢大家!
在我的应用程序中有一个ListFragment Activity。
我想为onItemClickedLongPress创建一个方法,当用户点击时,一个菜单就会弹出。
那么在ListFragment Activity中如何重写LongPress?
能给我点指导吗?谢谢大家!
@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);
}