如何保持一个alertdialog按钮的onclick开后触发? [英] How to keep an alertdialog open after button onclick is fired?

查看:110
本文介绍了如何保持一个alertdialog按钮的onclick开后触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主题有点儿说,这一切......我请求来自用户的PIN code,如果他们进入,点击OK按钮正和密码不正确,我想显示敬酒,但保持对话打开。它会自动关闭的那一刻......当然这是很琐碎的事情,以正确的,但找不到答案。

The subject kinda says it all.. I'm requesting a PIN code from the user, if they enter it, click the OK Positive Button and the PIN is incorrect I want to display a Toast but keep the dialog open. At the moment it closes automatically.. Sure this is very trivial thing to correct but can't find the answer yet.

谢谢..

推荐答案

建立一个自定义对话框与属性的android一个的EditText:密码=真按钮,然后手动设置的onClick监听器的按钮,并明确选择什么做吧。

Build a custom dialog with a EditText with the attribute android:password="true" a button, then manually set onClick listener the button, and explicitly choose what to do in it.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:minWidth="180dip" android:digits="1234567890" android:maxLength="4" android:password="true"/>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
         <Button android:id="@+id/Accept" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Accept" />
     </LinearLayout> 
    </LinearLayout>

如果你想让它弹出

然后:

Then when you want it to pop up:

final Dialog dialog = new Dialog(RealizarPago.this);
                dialog.setContentView(R.layout.custom_dialog);
                dialog.setTitle("PIN number:");
                dialog.setCancelable(true);

                Button button = (Button) dialog.findViewById(R.id.Accept);
                button.setOnClickListener(new OnClickListener() {
                @Override
                    public void onClick(View v) {
                        if(password_wrong){ 
                          //showToast
                        }else{
                          dialog.dismiss();
                          //other stuff to do
                        }
                    }
                }); 
                dialog.show();

这篇关于如何保持一个alertdialog按钮的onclick开后触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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