Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 오버로딩
- Menu
- 배열
- 생성자
- 에러페이지
- struts2
- 메서드
- 기본
- oracle
- 어노테이션
- 예외처리
- Spring
- paint
- 국제화
- AWT
- JSP
- 메소드
- Eclips
- layout
- mybatis
- HTML
- OGNL
- Java
- Graphic
- Android
- 전화걸기
- 이클립스
- JavaScript
- 안드로이드
- 클래스
Archives
- Today
- Total
note
Menu Xml (새로운 xml 파일 만들어 연결하기) 인플레이션 본문
new -> folder(만약 안드로이드 folder가 있으면 그것을 클릭)
생성하고자 하는 프로젝트의 res에 접근해 menu라는 폴더 생성
메뉴 폴더에 우클릭 후 new -> Other
menu.xml file 생성
메뉴
생성되면 하단에 menu.xml 에 접근하여
직접 코딩
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/seoul"
android:title="서울"
android:icon="@drawable/ic_launcher" />
<item android:id="@+id/busan"
android:title="부산"
android:icon="@drawable/ic_launcher" />
<item android:id="@+id/submenu"
android:title="기타" >
<menu>
<item android:id="@+id/suwon"
android:title="수원" />
<item android:id="@+id/jeju"
android:title="제주" />
</menu>
</item>
</menu>
package com.comonsware.android.menus3;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class MenuXmlDemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView myText = new TextView(this);
myText.setText("메뉴에서 도시를 선택하세요");
setContentView(myText);
}
//옵션 메뉴 생성
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
//메뉴 인플레이션
//res/menu/menu.xml에 사용할 메뉴를 정의한 후에 Activity에서 menu.xml에 정의된
//메뉴를 사용하고자 할때 MenuInfalter 객체를 생성해서 xml 형태의
//메뉴 정보를 읽어들여서 Activity에서 사용할 수 있는 형태로 가공해서 메뉴를 등록하는 작업 수행
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu,menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.seoul:
Toast.makeText(this,"서울", Toast.LENGTH_SHORT).show();
return true;
case R.id.busan:
Toast.makeText(this,"부산", Toast.LENGTH_SHORT).show();
return true;
case R.id.suwon:
Toast.makeText(this,"수원", Toast.LENGTH_SHORT).show();
return true;
case R.id.jeju:
Toast.makeText(this,"제주", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
}
'Android > 기본' 카테고리의 다른 글
| Message 팝업창 띄우기 경고창,토스트 표시,Progress Dialog (0) | 2012.01.11 |
|---|---|
| ConText Menu 메뉴 (길게 터치시 팝업메뉴) (0) | 2012.01.11 |
| 메뉴 Menu (0) | 2012.01.11 |
| 플리퍼 Flipper (화면을 동적으로 구현하고 싶을때 사용) (0) | 2012.01.11 |
| Intent Tab 권한설정, Manifest.xml(설정) (0) | 2012.01.10 |