본문 바로가기

Android

메뉴(menu) - 옵션 메뉴

package com.example.optionmenuex01;

 

import android.os.Bundle;

 

import android.app.Activity;

import android.view.Menu;

import android.view.MenuItem;

import android.view.SubMenu;

import android.widget.Toast;

 

public class MainActivity extends Activity {

 

     @Override

     protected void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);

           setContentView(R.layout.activity_main);

     }

 

     @Override

     public boolean onCreateOptionsMenu(Menu menu) {

           // Inflate the menu; this adds items to the action bar if it is present.

           MenuItem menu1 = menu.add(0, 1, 0, "짜장");

           menu1.setIcon(R.drawable.rating_good);

           menu.add(0, 2, 0, "짬뽕");

           menu.add(0, 3, 0, "우동");

           menu.add(0, 4, 0, "만두");

          

           SubMenu subMenu = menu.addSubMenu("기타");

           subMenu.add(0, 5, 0, "단무지");

           subMenu.add(0, 6, 0, "양파");       

           //getMenuInflater().inflate(R.menu.main, menu);

           return true;

     }

 

     @Override

     public boolean onOptionsItemSelected(MenuItem item) {

           // TODO Auto-generated method stub

           switch (item.getItemId()) {

           case 1:

                Toast.makeText(this, "짜장", Toast.LENGTH_SHORT).show();

                break;

           case 2:

                Toast.makeText(this, "짬뽕", Toast.LENGTH_SHORT).show();

                break;

           case 3:

                Toast.makeText(this, "우동", Toast.LENGTH_SHORT).show();

                break;

           case 4:

                Toast.makeText(this, "만두", Toast.LENGTH_SHORT).show();

                break;

           case 5:

                Toast.makeText(this, "단무지", Toast.LENGTH_SHORT).show();

                break;

           case 6:

                Toast.makeText(this, "양파", Toast.LENGTH_SHORT).show();

                break;

 

           default:

                break;

           }

          

          

           return false;

     }

       

}






 

'Android' 카테고리의 다른 글

메뉴 - context  (0) 2013.03.29
메뉴 - 체크메뉴  (0) 2013.03.29
셰이더 - ShapeDrawable  (0) 2013.03.29
셰이더 - 스윕 그래디언트 SweepGradient  (0) 2013.03.29
셰이더 - 원형 그래디언트 RadialGradient  (0) 2013.03.29