如何使用alertdialog [英] how to use alertdialog

查看:164
本文介绍了如何使用alertdialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package com.progme.wallkon;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class NextActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.next);

    ImageView im1;
    im1 = (ImageView)findViewById(R.id.a_01_b);
    im1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });

    ImageView im2;
    im2 = (ImageView)findViewById(R.id.a_02_b);
    im2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });

    ImageView im3;
    im3 = (ImageView)findViewById(R.id.a_03_b);
    im3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            showDialog(1);
        }
    });
}
            @Override
            protected Dialog onCreateDialog(int id) {

                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Gmelon");
                builder.setMessage("setting?");
                builder.setPositiveButton("YES",
                        new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.i("MyTag" , "Click YES");
                    }
                });

                builder.setNegativeButton("NO",
                        new android.content.DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.i("MyTag", "Click NO");
                    }
                });
                return builder.create();
            }
}

我写了code在activity.java这样的..

I wrote code in activity.java like this..

我想在IM1,IM2,IM3使用对话框,每必须得到另一个事件。
然后,我必须写3对话框?
以及如何我可以设置[// TODO自动...]在这里,我用的是如..
第一个对话框IM1,
第二个对话框IM2,
对于IM3 ..

I want to use dialog in im1, im2, im3, and each have to get another event. Then, I have to write 3 dialog? and how I can set [//TODO Auto...] here that I use is like.. first dialog for im1, second dialog for im2, third dialog for im3..

请帮助..

推荐答案

您可以写的警告对话框中的私有变量,并重新使用它,但不能在同一时间

You can write a private variable for the alert dialog and reuse it, but not at the same time

private AlertDialog mDialog = new AlertDialog.Builder(this)
            .setTitle("Gmelon")
            .setMessage("setting?")
            .setPositiveButton("YES",
                    new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.i("MyTag" , "Click YES");
                }
            })

            .setNegativeButton("NO",
                    new android.content.DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.i("MyTag", "Click NO");
                }
            }).create();

现在可以显示以往任何时候都在你的code想去的地方对话框。

now you can show the dialog where ever you want in your code.

这篇关于如何使用alertdialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆