on onCreate方法我使用setFocusable方法禁用所有editText。 但是点击按钮我想再次设置焦点。我已经实现了这个,但现在正在工作。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contactform);
name = (EditText) findViewById(R.id.name);
email = (EditText) findViewById(R.id.email);
address = (EditText) findViewById(R.id.address);
phone_number = (EditText) findViewById(R.id.phone_number);
name.setFocusable(false);
address.setFocusable(false);
phone_number.setFocusable(false);
email.setFocusable(false);
}
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.editButton:
Toast.makeText(this, "clicked", Toast.LENGTH_LONG).show();
name.setFocusable(true);
name.setFocusable(true);
address.setFocusable(true);
phone_number.setFocusable(true);
email.setFocusable(true);
break;
}
return super.onOptionsItemSelected(item);
}
答案 0 :(得分:0)
使用:
setFocusable(true)
setFocusableInTouchMode(true)
相反:
setEnabled(true)