Hello,
I have 2 classes that each have listview. I want both of these
listviews to access the same context menu, so I'm making a context
menu in a separate class.
Right now I only work with one of the class (that has listview) to see
if this can work. But apparently it can not. When I click and held the
listview, the context menu pops up. However, if I choose one of the
option nothing happened. It seems like the program never reach the
onContextItemSelected. I tried to debug it and see what happens, and
I get this message (whenever I clicked the contextmenu options) :
Window already focused, ignoring focus gain of:
com.android.internal.view.iinputmethodclient$stub$pr...@43c488f8
This is what I put in the class that has listview:
// ContextMenuClass makemenu = new ContextMenuClass();
// makemenu.menuFunction(mylistview);
And this is the ContextMenuClass i.e. the class that has contextmenu:
===ContextMenuClass.java===
public class ContextMenuClass extends Activity{
public void menuFunction(ListView listview) {
registerForContextMenu(listview);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo)menuInfo;
Log.d("Test", "oncreatecontextmenu is working");
menu.setHeaderTitle("Listview Number " + info.position);
menu.add(0, 1, 0, "OPTION_1");
}
@Override
public boolean onContextItemSelected (MenuItem item) {
Log.d("Test", "oncontextitemselected is working");
switch (item.getItemId()){
case 1:
Toast.makeText(this, "This is Option 1",
Toast.LENGTH_SHORT).show();
return true;
}
Log.d("Test", "return default");
return super.onContextItemSelected(item);
} }
=====================================================
Is separating onCreateContextMenu and onContextItemSelected from the
listview is the problem itself, or the problem comes from another
thing?
Any help will be much appreciated.
Thanks.
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en