所以,我想要做的是,如果名稱或聯繫人字段爲空,想要打印該消息,否則提交。 現在,問題是,對於第一次審判(兩個字段都是空的),它給了我'輸入名字'。那麼即使我再次輸入名字,仍然是一樣的。編輯文本值沒有變 - Android eclipse
能否請你幫我..
這裏是代碼...
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button sub=(Button) findViewById(R.id.submit);
final EditText name=(EditText) findViewById(R.id.editText1);
final EditText phone=(EditText) findViewById(R.id.editText2);
final String cust_name=name.getText().toString();
final String phone_num=phone. getText(). toString();
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(cust_name.length()==0)
Toast.makeText(MainActivity.this, "Name must be provided!", Toast.LENGTH_SHORT).show();
else if(phone_num.length()==0)
Toast.makeText(MainActivity.this, "You must provide your phone number!", Toast.LENGTH_SHORT).show();
else
{
Toast.makeText(MainActivity.this, "Success!", Toast.LENGTH_SHORT).show();
finish();
}
}
});
如果能幫助您解決問題,您可以接受我的解決方案。 –