[안드로이드,Android]메뉴 옵션

2013. 1. 24. 09:40Mobile/Android



반응형

 

 

 

 

 


package com.example.ggari_optionmenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		TextView tv = new TextView(this);
		tv.setText("아래 쪽 메뉴를 눌러봐요(까리)");
		setContentView(tv);
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0,1,0,"메뉴A"); //int groupId, int itemId, int order, CharSequence title
		menu.add(0,2,0,"메뉴B");
		SubMenu etc = menu.addSubMenu("etc");
		etc.add(0,3,0,"etc A");
		etc.add(0,4,0,"etc B");
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 1:
			Toast.makeText(this,"메뉴A~~~~",1).show();
			return true;
		case 2:
			Toast.makeText(this,"메뉴B~~~~~",1).show();
			return true;
		case 3:
			Toast.makeText(this,"etc A~~~~~~~~~",1).show();
			return true;
		case 4:
			Toast.makeText(this,"etc B ~~~~~",1).show();
			return true;
		}
		return false;
	}
}
반응형