添加的EditText来警告对话框。 [英] Adding EditText to Alert Dialog.

查看:232
本文介绍了添加的EditText来警告对话框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code表示创建警报对话框,我加了两个编辑文本,但一旦我运行的应用程序的的EditText内的值不会retrived和我的应用程序崩溃与NullPointerException异常:

在code是:

  AlertDialog.Builder警报=新AlertDialog.Builder(本);
        LayoutInflater充气= this.getLayoutInflater();
        最后的EditText usernameInput =(EditText上)findViewById(R.id.dialogusername);
        最后的EditText passwordInput =(EditText上)findViewById(R.id.dialogpassword);
        alert.setView(inflater.inflate(R.layout.dialog,NULL));
        alert.setTitle(请输入密码);
        alert.setMessage(请输入密码,删除应用程序:);
        alert.setPositiveButton(OK,新DialogInterface.OnClickListener(){
        公共无效的onClick(DialogInterface对话,诠释whichButton){
            //提供用户谨慎卸载前
            //这里还应该补充的是要读的密码AsyncTask的,一旦其检查密码是正确的应用程序将被删除
            值1 = usernameInput.getText()的toString()。
            值2 = passwordInput.getText()的toString()。
            如果(value1.equals(空)及和放大器; value2.equals(空))
            {Toast.makeText(背景下,输入用户名和密码,Toast.LENGTH_SHORT).show();}
         }
        });
        });
        alert.show();
 

解决方案

谢谢你们在回答我的问题你的贡献,我觉得我得到了我张贴的问题的解决方案上面是:

  AlertDialog.Builder警报=新AlertDialog.Builder(MyFeedActivity.this);
        LayoutInflater充气= MyFeedActivity.this.getLayoutInflater();
        //这是我做过什么,以增加布局的警告对话框
        查看布局= inflater.inflate(R.layout.dialog,NULL);
        alert.setView(布局);
        最后的EditText usernameInput =(EditText上)layout.findViewById(R.id.dialogusername);
        最后的EditText passwordInput =(EditText上)layout.findViewById(R.id.dialogpassword);
 

和我想的问题是,我不能得到EidtText警告对话框内,而是由上面code做的每一件事只是罚款和我在一起。

I have the following code that create alert dialog and I added two edit text to it but once I run the app the values within the EditText won't be retrived and my app crash with NullPointerException:

the code is:

AlertDialog.Builder alert = new AlertDialog.Builder(this);
        LayoutInflater inflater=this.getLayoutInflater();
        final EditText usernameInput=(EditText)findViewById(R.id.dialogusername);
        final EditText passwordInput=(EditText)findViewById(R.id.dialogpassword);   
        alert.setView(inflater.inflate(R.layout.dialog,null));
        alert.setTitle("Enter Password");
        alert.setMessage("Enter password to remove the app:");
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            //provide user with caution before uninstalling
            //also here should be added a AsyncTask that going to read the password and once its checked the password is correct the app will be removed
            value1=usernameInput.getText().toString();
            value2=passwordInput.getText().toString();
            if(value1.equals(null)&&value2.equals(null))
            {Toast.makeText(context, "Enter username and password", Toast.LENGTH_SHORT).show();}
         }
        });
        });
        alert.show();

解决方案

Thanks guys for your contributions in answering my question, and I think I got the solution for the problem that I posted above which is:

AlertDialog.Builder alert = new AlertDialog.Builder(MyFeedActivity.this);
        LayoutInflater inflater=MyFeedActivity.this.getLayoutInflater();
        //this is what I did to added the layout to the alert dialog
        View layout=inflater.inflate(R.layout.dialog,null);       
        alert.setView(layout);
        final EditText usernameInput=(EditText)layout.findViewById(R.id.dialogusername);
        final EditText passwordInput=(EditText)layout.findViewById(R.id.dialogpassword);

and I think the problem was that I cannot get the EidtText within the alert dialog, but by doing it by the above code every thing works just fine with me.

这篇关于添加的EditText来警告对话框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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