How set focus on View Android development example

Set focus on a View in Android application example source code for Button, EditText, View, TextView, isFocused(), requestFocus() .

// set focus on Button Android example
 private Button mRightButton;
 mRightButton = (Button) a.findViewById(R.id.rightButton);
 mRightButton.requestFocus();
// boolean isFocused() 
boolean b = mRightButton.isFocused(); // true or false
 
// set focus on TextView directly Android example
((TextView) findViewById(R.id.myText)).requestFocus();
 
// set focus on View Android example
private View mView;
mView = findViewById(R.id.showAll);
mView.requestFocus();
 
// set focus on EditText Android example
private EditText mEdit;
mEdit = (EditText)findViewById(R.id.myEdit);
mEdit.requestFocus();
This entry was posted in Android Examples Code and tagged , , . Bookmark the permalink.


Comments are closed.



24,096 views