一个应用程序具有如下的GridView:
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:horizontalSpacing="0dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp" />
以下代码用于检测焦点变化:
gridview.setOnFocusChangeListener((v, hasFocus) -> {
if(hasFocus){
utility.showMessage(OnviferActivity.this, "Gained Focus");
gridview.setFocusable(true);
}else{
utility.showMessage(OnviferActivity.this, "Lost Focus");
gridview.setFocusable(true);
}
});
使用D-pad将焦点移出GridView后,除非重新启动活动,否则它将永远不会重新获得它。可以将所选内容移至GridView内的项目,但GridView不会集中。使用方向键选择项目时,状态为state_pressed,而不是state_selected。真的很奇怪。
有人能对此有所启发吗?