onContextItemSelected not called in fragment

907 views
Skip to first unread message

Gilush

unread,
Jul 31, 2012, 4:55:50 PM7/31/12
to actionba...@googlegroups.com
hey, im using fragment in my app and i have 2 fregment with lists that i want to implemente long click. 

I implemented both in fregment a and b. and when i long pressed in b list setOnCreateContextMenuListener open correctly but it use onContextItemSelected from a activity?!?

I read about jack answer and change MenuItem to android.view.MenuItem but still not working. 

Now i commented registerForContextMenu() in fregment a and onContextItemSelected never called in fregment b

My code:

@Override

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) 

{

AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;

menu.setHeaderTitle(m_ArraylistGames.get(info.position).m_Title);

String[] menuItems = getResources().getStringArray(R.array.games_array);

for (int i = 0; i<menuItems.length; i++) {

menu.add(Menu.NONE, i, i, menuItems[i]);

}

}

@Override

public boolean onContextItemSelected(MenuItem item) {

Adapte rView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();

int menuItemIndex = item.getItemId();

switch (menuItemIndex)

{

case 0:
.
.
.

break;

case 1:
.
.
.

break;

default:

break;

}


return true;

}


ANY IDEA? 

Jake Wharton

unread,
Jul 31, 2012, 5:31:36 PM7/31/12
to actionba...@googlegroups.com
The context menu dispatching is handled by the Activity and FragmentManager. ABS does not affect this. Make sure your method signatures are correct for the correct types by including @Override annotations. Other than that, the behavior is native to whatever the support library does.

---
Jake Wharton
http://about.me/jakewharton
Reply all
Reply to author
Forward
0 new messages