This is kind of a repost, and I apologize for any broken rules, but I have a couple of questions about the soft keyboard on Android phones:
1) I have an Android app with a couple different views (that the user switches between). How can I determine which is the current view?? I need to get the current view to execute the code that hides the virtual keyboard.
2) How can I check whether the virtual keyboard is currently being displayed (so I can filter the actions of my开发者_JAVA百科 various hard keys)??
Thanks, R.
1) public class ViewIdentification extends Activity implements OnFocusChangeListener{
EditText _edt1;
EditText _edt2;
EditText _edt3;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_edt1 = (EditText)findViewById(R.id.EditText01);
_edt1.setOnFocusChangeListener(ViewIdentification.this);
_edt2 = (EditText)findViewById(R.id.EditText02);
_edt2.setOnFocusChangeListener(ViewIdentification.this);
_edt3 = (EditText)findViewById(R.id.EditText03);
_edt3.setOnFocusChangeListener(ViewIdentification.this);
}
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(v == _edt1 && hasFocus == true){
Toast.makeText(ViewIdentification.this, "The First EditText is focused now", Toast.LENGTH_LONG).show();
}else if(v == _edt2 && hasFocus == true){
Toast.makeText(ViewIdentification.this, "The Second EditText is focused now", Toast.LENGTH_LONG).show();
}else if(v == _edt3 && hasFocus == true){
Toast.makeText(ViewIdentification.this, "The Third EditText is focused now", Toast.LENGTH_LONG).show();
}
}
}
NOTE : In this way we can get to know which view is focused .
2)
This can be done by calculating the size of the activity ( the location at which the last focused view is at ) .
精彩评论