2010/04/03
[Study Note] Options 메뉴 제어하기~~
onPrepareOptionsMenu 를 이용하면 구성된 메뉴가 활성화 되기 전에 필요한 처리를 할 수 있다.
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/MnuNew"
android:title="New"
android:icon="@drawable/icon"
/>
<item
android:title="selection"
>
<menu>
<item
android:id="@+id/MnuSelection1"
android:title="Selection1"
android:icon="@drawable/icon"
/>
<item
android:id="@+id/MnuSelection2"
android:title="Selection2"
/>
<item
android:id="@+id/MnuSelection3"
android:title="Selection3"
/>
</menu>
</item>
<item
android:id="@+id/MnuEdit"
android:title="Modify"
android:checkable="true"
android:icon="@drawable/icon"
/>
</menu>
package com.neodreamer.MyMenu;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MyMenu extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public boolean onCreateOptionsMenu( Menu menu )
{
Log.i("Notice", "onCreateOptionsMenu");
// XML menu resource 를 이용한 메뉴 구성
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.myoptions, menu);
return true;
}
public boolean onPrepareOptionsMenu( Menu menu )
{
MenuItem chItem = menu.findItem( R.id.MnuEdit );
chItem.setTitle( "Delete" );
return true;
}
public boolean onOptionsItemSelected( MenuItem item )
{
Log.i("Notice", "onOptionsMenuSelected");
switch ( item.getItemId() )
{
case R.id.MnuNew:
Log.i("XML", "MnuNew");
break;
case R.id.MnuSelection1:
Log.i("XML", "MnuSelection1");
break;
case R.id.MnuSelection2:
Log.i("XML", "MnuSelection2");
break;
case R.id.MnuSelection3:
Log.i("XML", "MnuSelection3");
break;
case R.id.MnuEdit:
Log.i("XML", item.toString() );
break;
}
return false;
}
}
Labels:
Android
,
Android Development
,
Options Menu
,
TistoryOldPost
,
안드로이드 개발
,
안드로이드 옵션 메뉴
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment