清除編輯文本我想清除或說重置editText,同時單擊清除表單按鈕。我無法清除editText框。這是我的完整代碼:無法使用edittext.setText(「」)在android
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_us);
et1 = (EditText) findViewById(R.id.editText1); //name
et3 = (EditText) findViewById(R.id.editText3); //email
et2 = (EditText) findViewById(R.id.editText2); //feedback
Button submit1 = (Button) findViewById(R.id.button1);
//submit1.setOnClickListener(this);
Button clear=(Button)findViewById(R.id.button2);
//clear.setOnClickListener(this);
submit1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if(view==submit1)
{
if(et1.getText().toString().length()==0 || et2.getText().toString().length()==0
|| et3.getText().toString().length()==0)
{
Toast t1=Toast.makeText(getApplicationContext(), "Please fill all the forms",
Toast.LENGTH_LONG);
t1.show();
}
else
{
String email = "[email protected]";
String sub1=spin.getSelectedItem().toString();
String message = et2.getText().toString();//body
String name = et1.getText().toString();
String from=et3.getText().toString();
String emailPattern = "[a-zA-Z0-9._-][email protected][a-z]+\\.+[a-z]+";
if(from.matches(emailPattern))
{
String body="Name :"+name+"\n"+"Email ID :"+ from+"\n"+"Feedback :"+message;
sendMail(email,sub1,from, body);
}
else
{
Toast.makeText(getApplicationContext(), "Invalid Email ID", Toast.LENGTH_SHORT).show();
et3.setText("");
}
}
}
else if(view==clear)
{
et1.setText("");
et2.setText("");
et3.setText("");
}
}
});
}
任何變化.. ??我要去哪裏錯了..?請幫我...
你是什麼意思'無法清除'? – Kedarnath
CHK此, http://stackoverflow.com/questions/7241808/how-to-reset-edittext-after-an-action-has-been-completed – messi