context menus and the back button

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

context menus and the back button

Postby kanzlr » Sat Mar 21, 2009 12:29 pm

hi there.

I have a little problem with context menus.
In my app, a long press on a listview row opens a context menu. but how can the user close it again?
if the back button is pressed, the whole activity closes and we go back by one screen. thats not what I had in mind.
with the on board apps, the back button just closes the menu. should i just catch the back key?

thanks
Bernhard
kanzlr
Developer
Developer
 
Posts: 25
Joined: Sun Mar 15, 2009 4:44 pm
Location: Vienna/Austria/EU

Top

Postby gayathri239 » Mon Mar 23, 2009 12:27 pm

When you press the back button, it automatically closes the context menu.. no need for capturing the back button..
the below one worked fyn for me..

listView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

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

menu.setHeaderTitle("Menu");
menu.add(0, 0, 0, "Menu1");
menu.add(0, 1, 1, "Menu2");
menu.add(0, 2, 2, "Menu3");

}
});

public boolean onContextItemSelected(MenuItem item) {
switch (<expression>) {
case 0: <some code>
break;
<rest cases>
}
return true;
}
gayathri239
Freshman
Freshman
 
Posts: 2
Joined: Thu Jan 15, 2009 4:44 am

Postby kanzlr » Mon Mar 23, 2009 1:44 pm

yes I know, thanks.

the problem is, that pressing the back button also closes the activity that spawned the context menu...solution for now: i added a "cancel" option to the context menu...not very elegant :)
kanzlr
Developer
Developer
 
Posts: 25
Joined: Sun Mar 15, 2009 4:44 pm
Location: Vienna/Austria/EU

Postby kanzlr » Mon Mar 23, 2009 7:00 pm

sorry, I've just been stupid...had a "finish()" in my onKeydown listener for the back button...brrrrr.

:)
kanzlr
Developer
Developer
 
Posts: 25
Joined: Sun Mar 15, 2009 4:44 pm
Location: Vienna/Austria/EU

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 13 guests