1) ViewIdentification public class activité met en œuvre 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: De cette façon, nous pouvons apprendre à connaître quelle vue est axé .
2)
Cela peut être fait en calculant la taille de l'activité (l'endroit où la dernière vue est focalisée à).