阳光网驿-企业信息化交流平台【DTC零售连锁全渠道解决方案】

 找回密码
 注册

QQ登录

只需一步,快速开始

扫描二维码登录本站

手机号码,快捷登录

老司机
查看: 955|回复: 0

[转帖] Android AlertDialog 使用方法

[复制链接]
  • TA的每日心情
    开心
    2012-3-7 10:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2012-1-7 11:11:20 | 显示全部楼层 |阅读模式
    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.DialogInte**ce;

    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 DialogInte**ce.OnClickListener() {
    public void onClick(DialogInte**ce dialog, int whichButton) {
    setResult(RESULT_OK);
    finish();
    }
    })
    .setNegativeButton(“No”, new DialogInte**ce.OnClickListener() {
    public void onClick(DialogInte**ce 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 DialogInte**ce.OnClickListener() {
    public void onClick(DialogInte**ce 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 DialogInte**ce.OnClickListener() {
    public void onClick(DialogInte**ce dialog, int whichButton)
    {

    }
    })
    .show();
    }
    })
    .show();
    }
    });
    }
    }
    楼主热帖
    启用邀请码注册,提高发帖质量,建设交流社区
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

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