保留对话框,直到验证字段

时间:2014-10-24 06:02:33

标签: android

显示一个对话框,如图像所示,当文件被验证时,只有对话框应该消失,直到它应该retian ..我想只有在字段被验证时才将数据发送到服务器..请帮忙。

enter image description here

               alertotp=new AlertDialog.Builder(Streaming_Login.this);
                LayoutInflater inflaterotp=Streaming_Login.this.getLayoutInflater();
                View layoutotp=inflaterotp.inflate(R.layout.otp, null);
                alertotp.setView(layoutotp);
                final TextView txtref=(TextView) layoutotp.findViewById(R.id.txtotpref);
                final EditText edtotp=(EditText) layoutotp.findViewById(R.id.edtotp);
                final EditText edtotppwd=(EditText) layoutotp.findViewById(R.id.edtotppwd);
                final EditText edtotpcnfrm=(EditText) layoutotp.findViewById(R.id.edtoptcnfrmpwd);
                txtref.setText("Reference number is: " +rslt);

                alertotp.setTitle("Change Password");
                //alertotp.setCancelable(false);
                alertotp.setPositiveButton("OK",new DialogInterface.OnClickListener() {

                    @SuppressLint("NewApi")
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        String strotp=edtotp.getText().toString().trim();
                        String strpwd=edtotppwd.getText().toString().trim();
                        String strcnfrmpwd=edtotpcnfrm.getText().toString().trim();
                        ArrayList<NameValuePair> postParameters=new ArrayList<NameValuePair>();
                        postParameters.add(new BasicNameValuePair("userId", user));
                        postParameters.add(new BasicNameValuePair("otp", strotp));
                        postParameters.add(new BasicNameValuePair("refId", rslt));
                        postParameters.add(new BasicNameValuePair("password", strpwd));


                        final TextView txtot=new TextView(Streaming_Login.this);
                        txtot.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                String straftrotp=txtot.getText().toString().trim();
                                System.out.println("The result after sending otp is ..." +straftrotp);
                                if(straftrotp.equals("SUCCESS"))
                                {
                                    Toast.makeText(getApplicationContext(), "Password has been changed succesfully...", Toast.LENGTH_LONG).show();
                                }
                            }
                        });
                        synchronized (txtot) {
                            if(user.equals("") || strotp.equals("") || rslt.equals("") || strpwd.equals(""))
                            {
                                //alertotp.setCancelable(false);

                                Toast.makeText(getApplicationContext(), "No field should be empty....", Toast.LENGTH_LONG).show();
                            }
                            else{

                                if(strpwd.equals(strcnfrmpwd))
                                {

                                    new CustomHttpClient().executeHttpPost(httpUrlchngpwd, postParameters, txtot);
                                }
                                else
                                {
                                    //alertotp.setCancelable(false);
                                    Toast.makeText(getApplicationContext(), "The password and confirm password are not same please try again....", Toast.LENGTH_LONG).show();

                                }

                            }
                        }

                    }
                });
                alertotp.show();

1 个答案:

答案 0 :(得分:0)

您始终可以获取文本字段的值并进行比较以查看它是否为空

String str = edtotp.getText().toString();
if( str.length() !=0 ){ //or str.isEmpty() from API 9
//the field has text
} else {
//the field is empty
}

您还可以使用验证

等功能
str.contains("v"); //for specific characters
str.endsWith("value"); //the prefix of the string
str.startsWith("value"); //the end of it
str.equals("Value"); //is it equal to the needed value
str.equalsIgnoreCase("Value"); //same, just ignores the case of letters

您还可以转换,格式化,连接,修剪,子串等。 有用的链接

String class

Integer class

Pattern class