Android Intents: A Listview With Menu And Submenu
Hi, Everyone. I would like to display a sub menu when I click a specific item. For instance, clicking Play Video shows a sub menu with 2 more items: Play It and Show playlist. Is
Solution 1:
You might try to implement it like the following code:
publicvoidshowPopup(View v) {
finalPopupMenupopup=newPopupMenu(this, v);
finalMenuInflaterinflater= popup.getMenuInflater();
inflater.inflate(R.menu.actions, popup.getMenu());
popup.setOnMenuItemClickListener(newPopupMenu.OnMenuItemClickListener() {
@OverridepublicbooleanonMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.play_video:
//intent = YouTubeIntents.createPlayVideoIntentWithOptions(this,// VIDEO_ID, true, false);//startActivity(intent);
Toast.makeText(TestActivity.this, "play video", Toast.LENGTH_LONG).show();
returntrue;
case R.id.show_playlist:
//intent = YouTubeIntents.createOpenPlaylistIntent(this, PLAYLIST_ID);//startActivity(intent);
Toast.makeText(TestActivity.this, "show playlist", Toast.LENGTH_LONG).show();
returntrue;
default:
returnfalse;
}
}
});
popup.show();
}
with actions.xml in res/menu folder:
<?xml version="1.0" encoding="utf-8"?><menuxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:id="@+id/play_video"android:title="Play Video"android:showAsAction="ifRoom"/><itemandroid:id="@+id/show_playlist"android:title="Show playlist" /></menu>
It's actually just similar to way mentioned in the documentation
Post a Comment for "Android Intents: A Listview With Menu And Submenu"