Android Lab Test : Creating a menu context (english)
Video of tutorial on : https://www.youtube.com/playlist?list=PLL2Z3bzdO25yHwIV3XdMzKs61At0Ldh6L
Visit http://www.AndroidLabTest.com
Android Lab Test : Creating a menu context (english)
1. Develop on Android
Android Lab Test
www.AndroidLabTest.com
Youku
By Bruno Delb
www.weibo.com/brunodelb
i.youku.com/brunodelb | www.weibo.com/brunodelb | blog.delb.cn
http://i.youku.com/brunoparis
Weibo
Officialsite
Lesson : The contextual menu
2. The contextual menu
• In this lesson, you will learn to add a
contextual menu to a view.
• For this, you will use the methods of the
ContextMenu.
3. The contextual menu
• In first, the contextual menu shoud be attached to an object, for
example to a button :
registerForContextMenu(btnMenu);
4. The contextual menu
• The contextual menu should be created with the method
onCreateContextMenu().
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
getMenuInflater().inflate(R.menu.contextmenu, menu);
menu.setHeaderTitle("Choose an option");
}
5. The contextual menu
• To each selection of an option of the contextual menu,
the method onContextItemSelected() is called with in his
parameter the selected item (MenuItem).
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.option1: return true;
case R.id.option2: return true;
case R.id.option3: return true;
}
return super.onContextItemSelected(item);
}
11. Follow me on my channel PengYooTV …
On my Youku channel
http://i.youku.com/brunoparis
Who am I ?
Bruno Delb (www.delb.cn),
Author of the first french book of development of Java mobile application (2002),
Consultant, project manager and developer of social & mobile applications,
let’s talk about your needs ...
And on Weibo :
http://www.weibo.com/brunodelb