Showing posts with label Options Menu. Show all posts
Showing posts with label Options Menu. Show all posts
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
,
안드로이드 개발
,
안드로이드 옵션 메뉴
2010/03/31
[Study Note] Options 메뉴 다루기
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
// 추가하기 위한 메뉴를 위한 상수
static final int MENU_NEW = 1;
static final int MENU_EDIT = 2;
static final int MENU_SEL = 3;
static final int MENU_CHECK = 4;
// 추가하기 위한 서브 메뉴를 위한 상수
static final int MENU_SEL_1 = 5;
static final int MENU_SEL_2 = 6;
static final int MENU_SEL_3 = 7;
public boolean onCreateOptionsMenu( Menu menu )
{
super.onCreateOptionsMenu( menu );
menu.add( 0, MENU_NEW, 0, "NEW" ) // New 메뉴 추가
.setAlphabeticShortcut( 'n' ); // 단축키 지정
menu.add( 0, MENU_CHECK, 0, "CHECK" ) // Check 메뉴 추가
.setCheckable( true ); // 체크 옵션 추가
menu.add( 0, MENU_EMPTY, 0, "Empty" ) // Empty 메뉴 추가
.setCheckable( true ); // 체크 옵션 추가
SubMenu sub = menu.addSubMenu( "Select" ); // Select 서브 메뉴 추가
sub.add( 0, MENU_SEL_1, 0, "Selection 1" ); // 메뉴 추가
sub.add( 0, MENU_SEL_2, 0, "Selection 2" ); // 메뉴 추가
sub.add( 0, MENU_SEL_3, 0, "Selection 3" ); // 메뉴 추가
return true;
}
public boolean onOptionsItemSelected( MenuItem item )
{
switch ( item.getItemId() )
{
case MENU_NEW:
{
// Alert 대화상자 생성
AlertDialog alert = new AlertDialog.Builder( this )
.setTitle( "타이틀" )
.setMessage( "메세지" )
.setPositiveButton( "OK",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
}
)
.setNeutralButton( "?",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
}
)
.setNegativeButton( "Cancel",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
}
)
.create();
alert.show();
}
return true;
}
return false;
}
Original Post : http://neodreamer-dev.tistory.com/395
Labels:
Android
,
Options Menu
,
TistoryOldPost
,
메뉴
,
안드로이드
Subscribe to:
Posts
(
Atom
)