码迷,mamicode.com
首页 > 其他好文 > 详细

简单的menu和点击(包括alertDialog定制)

时间:2014-07-07 15:18:20      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:android   os   cti   io   new   res   

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

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.
super.onCreateOptionsMenu(menu);
menu.add(0, 0, 0, "菜单项一");
menu.add(0, 1, 0, "菜单项二");
menu.add(0, 2, 0, "菜单项三");
return true;

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub


Dialog alertDialog = new AlertDialog.Builder(this).
setTitle("你点击了").
setMessage((String)item.getTitle()).
setIcon(R.drawable.ic_launcher).
setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
setNegativeButton("取消", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
setNeutralButton("查看详情", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
create();
alertDialog.show();

return true;

}


}

简单的menu和点击(包括alertDialog定制),布布扣,bubuko.com

简单的menu和点击(包括alertDialog定制)

标签:android   os   cti   io   new   res   

原文地址:http://www.cnblogs.com/honeynm/p/3815218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!