六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 49|回复: 0

Android AlertDialog 使用方法

[复制链接]

升级  54.33%

109

主题

109

主题

109

主题

举人

Rank: 3Rank: 3

积分
363
 楼主| 发表于 2013-1-15 02:59:41 | 显示全部楼层 |阅读模式
看看這個程序,基本就會使用他了.

  • package maximyudin.AlertDialogBuilderSample;
  • import android.app.Activity;
  • import android.os.Bundle;
  • import android.widget.Button;
  • import android.view.View;
  • import android.app.AlertDialog;
  • import android.content.DialogInterface;
  • public class AlertDialogBuilderSample extends Activity {
  • @Override
  • public void onCreate(Bundle icicle) {
  • super.onCreate(icicle);
  • setContentView(R.layout.main);
  • final Button btnQuit = (Button) findViewById(R.id.btnQuit);
  • btnQuit.setOnClickListener(new Button.OnClickListener() {
  • public void onClick(View v) {
  • new AlertDialog.Builder(AlertDialogBuilderSample.this)
  • .setTitle(“Question”)
  • .setMessage(“Are you sure that you want to quit?”)
  • .setIcon(R.drawable.question)
  • .setPositiveButton(“Yes”, new DialogInterface.OnClickListener() {
  • public void onClick(DialogInterface dialog, int whichButton) {
  • setResult(RESULT_OK);
  • finish();
  • }
  • })
  • .setNegativeButton(“No”, new DialogInterface.OnClickListener() {
  • public void onClick(DialogInterface dialog, int whichButton) {
  • }
  • })
  • .show();
  • }
  • });
  • final Button btnTravels = (Button) findViewById(R.id.btnTravels);
  • btnTravels.setOnClickListener(new Button.OnClickListener() {
  • public void onClick(View v) {
  • new AlertDialog.Builder(AlertDialogBuilderSample.this)
  • .setTitle(“I want to go to”)
  • .setItems(R.array.items_indide_dialog,
  • new DialogInterface.OnClickListener() {
  • public void onClick(DialogInterface dialog, int whichcountry) {
  • String[] travelcountries =
  • getResources().getStringArray(R.array.items_indide_dialog);
  • new AlertDialog.Builder(AlertDialogBuilderSample.this)
  • .setMessage(“I’m going to “ + travelcountries[whichcountry])
  • .setNeutralButton(“Cancel”,
  • new DialogInterface.OnClickListener() {
  • public void onClick(DialogInterface dialog, int whichButton)
  • {
  • }
  • })
  • .show();
  • }
  • })
  • .show();
  • }
  • });
  • }
  • }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表