简体   繁体   English

将EditText中的文本控制到AlertDialog中

[英]Control text in EditText into AlertDialog

I try to check the insert text from user into AlertDialog with this: 我尝试使用以下方法检查用户到AlertDialog中的插入文本:

builder.setPositiveButton(
                getString(R.string.search_button),
                new DialogInterface.OnClickListener() {
                    public void onClick(
                            DialogInterface dialog,
                            int id) {


                        mNome = editext.getText().toString();
                        mCognome = editext1.getText().toString();

                        View focusView = null;



                        if (TextUtils.isEmpty(mNome) && TextUtils.isEmpty(mCognome)) {
                            editext.setError(getString(R.string.error_field_required));
                            focusView = editext;
                            cancel=true;
                            focusView.requestFocus();

                        }
                        else{
                        dialog.dismiss();

                        go();}

                    }
                });

        mAlertDialog = builder.create();
        mAlertDialog.show();

But not work, the if the text is empty the AlertDialog disappears 但不起作用,如果文本为空,则AlertDialog消失

Use this 用这个

                 edittext.requestFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

I had the same problem, so check your String like this : 我有同样的问题,所以像这样检查您的String

if(Your_String == null) or if(Your_String.isEmpty()) if(Your_String == null) if(Your_String.isEmpty())

Hope it will work. 希望它能工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM