Friday, 11 September 2015

long press menu (called context menu )

We create a xml file for the menu show as done in the previous post

to create context menu

we get reference for a button and register it for context menu

Button button= (Button) findViewById(R.id.button);
registerForContextMenu(button);
 
then we modify oncreate context menu
 
@Overridepublic void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
                   super.onCreateContextMenu(menu, v, menuInfo);

    MenuInflater menuInflater= getMenuInflater();
    menuInflater.inflate(R.menu.contextm,menu);
}
 
 the above does the job of creating context menu

now , what if any of the option clicked

we redefine onContextItemSelected

No comments:

Post a Comment