Hello, today I resolved a focus problem. Hope this will give you some help.
The keypoint lies in the 'touchMode' of android. Developer from JavaSpring platfrom will concentrate on setFocusable()and requestFocus(). But there are two others functions in Android: setFocusableInTouchMode() and requestFocusFromTouch(). These two are the keypoint for focus problem in Android.
And there is a isInTouchMode() function in class 'View', this can help us monitor whether click() is exeucted during 'Focuse' event time. You can see the codes below:
ImageButton.OnFocusChangeListener mFocusChangeListener = new ImageButton.OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus) {
Log.d("FocuseChange", "Focuse has changed.");
if (hasFocus) {
// If it is touchmode, click is executed. Otherwise it is on be highlighted
v.setBackgroundDrawable(getResources().getDrawable (R.drawable.));
if (v.isInTouchMode()){
((ImageButton)v).performClick();
}
} else {
v.setBackgroundDrawable(getResources().getDrawable (R.));
v.getBackground().setAlpha(100);
}
}
};