Long click on the button to open the menu. in java class: public class ContextmenuActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b=(Button)findViewById(R.id.button1); registerForContextMenu(b); } //create the menuuu====================== @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater=getMenuInflater(); inflater.inflate(R.layout.contextmenu, menu); } //click to each menu====================== @Override public boolean onContextItemSelected(MenuItem item) { // TODO Auto-generated method stub if(item.getItemId()==R.id.item1) ...
A blog where you can find all codes for Android, Corona, Basic tutorials, Interview questions and more...