今天试跑了"Google Android SDK开发范例大全源码里的EX04_02工程",发现mImageButton1.setOnFocusChangeListener这个监听器木有反应。查了很多资料发现原因是:在Android
TouchMode模式下是不存在focus的。所谓的focus是指被选中的意思,类似于windows平台下单击一个文件夹后鼠标的焦点(focus)就在该文件夹上面。既然不存在focus,也就不存在FocusChange的问题,所以setOnFocusChangeListener监听器不起作用也就可以理解。如果想在TouchMode下面使用这个监听器可以使用如下两种方法:
1.增加一句代码:mImageButton1.setFocusableInTouchMode(true)
2.在main.xml中mImageButton标签中加入一个子标签:android:focusableInTouchMode="true"。这两种方法的作用都是使得focus在TouchMode下恢复作用。
关于TouchMode可以参考下面两片文章:
1.http://developer.android.com/resources/articles/touch-mode.html
2.http://hi.baidu.com/qmiao128/blog/item/3bc40f54e0605144574e0048.html