Android:清除EditText

时间:2015-12-01 14:59:09

标签: android android-edittext

我的EditText出现问题,点击注册按钮后,我在EditText中输入的数据仍然存在。我在清除EditText时尝试了一些代码,但它不起作用。

public void onSignUpClick(View v)
        {
            if(v.getId() == R.id.Bsignupbutton)
            {
                EditText name = (EditText)findViewById(R.id.TFname);
                EditText email = (EditText)findViewById(R.id.TFemail);
                EditText uname = (EditText)findViewById(R.id.TFuname);
                EditText pass1 = (EditText)findViewById(R.id.TFpass1);
                EditText pass2 = (EditText)findViewById(R.id.TFpass2);



                String namestr = name.getText().toString();
                String emailstr = email.getText().toString();
                String unamestr = uname.getText().toString();
                String pass1str = pass1.getText().toString();
                String pass2str = pass2.getText().toString();



                if(!pass1str.equals(pass2str))
                {

                    Toast pass = Toast.makeText(Signup.this, "Password don't match!", Toast.LENGTH_SHORT);
                    pass.show();


                }
                else
                {
                    Contact c = new Contact();
                    c.setName(namestr);
                    c.setEmail(emailstr);
                    c.setUname(unamestr);
                    c.setPass(pass1str);

                    helper.insertContact(c);
                }

            }
        }

1 个答案:

答案 0 :(得分:0)

在您的情况下使用此方法:

void clearFields() {
    name.setText("");
    email.setText("");
    uname.setText("");
    pass1.setText("");
    pass2.setText("");
}