In my activity there is an option menu, for an item there is a submenu. I want for a submenu item below will come
i have xml like this,
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/file"
android:icon="@drawable/file"
android:title="@string/file" >
<!-- "file" submenu -->
<menu>
<item android:id="@+id/create_new"
android:title="@string/create_new" />
<item android:id="@+id/open"
android:title="@string/open" />
</menu>
</item>
</menu>
I know for option menu it is po开发者_如何转开发ssible but i want to put for a submenu item. How can i do that? Is there any other way to do this?
You should display your own dialog isntead of using menu:
http://developer.android.com/guide/topics/ui/dialogs.html
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
You can override the menu button from onkeyDown() method and can show this dialog show it will be displayed as a menu itself.....!
The code will be like this:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
//return super.onKeyDown(keyCode, event);
if(keyCode==KeyEvent.KEYCODE_MENU){
// now create your dialog here
return true;
}
return false;
}
You can use spinner:
String na[] = new String[namelist.size()];
Spinner spinname =(Spinner)findViewById(R.id.networkname);
ArrayAdapter<String> adapter=new ArrayAdapter<String>this,android.R.layout.simple_spinner_item,na);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinname.setAdapter(adapter);
精彩评论