ListFragment アクティビティがあります。
ユーザーがこれを行うときに、onItemClickedLongPress のメソッドを作成したいと考えています。メニューがポップアップします。メニュー作りに慣れてきました。
誰かがよろしければ、ListFragmentアクティビティで長押しをオーバーライドする方法についてさらに説明してください。
編集:このサンプルは、システムメニュー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インテリセンスは「良い」setOnLongClickListener
とは言えなかったのでListView
(ListView
少なくとも2つsetOnLongClickListener
のメソッドがあるため...クラスView
から1つと2つ目)...最も簡単な方法は、実装してからコードを追加することです。AdapterView
ListFragment
AdapterView.OnItemLongClickListener
onViewCreated
getListView().setOnLongClickListener(this);
「長押し」とは、コンテキストメニューを指していると思います。の場合はListFragment
、コンテキスト メニューに登録するだけです。
@Override
public void onActivityCreated(Bundle icicle) {
registerForContextMenu(getListView());
}
これを行うと、ListFragment
が呼び出さonCreateContextMenu()
れonContextItemSelected()
、長押しが検出されたときに呼び出されます。
Erich Douglass の回答をさらに修正しました。次のように、コードを修正して onViewCreated に登録するまで、何らかの理由で自分のアプリがクラッシュしました。
@Override
public void onViewCreated (View view, Bundle savedInstanceState) {
registerForContextMenu(getListView());
}