在我的應用程序中有一個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);
}
參照:https://github.com/lorensiuswlt/NewQuickAction