您可以扩展ListView
类和覆盖requestLayout()
方法。ListView
当完成更新并窃取焦点时,将调用该方法。因此,在此方法结束时,您可以将焦点返回到您的TextView
.
public class ExampleListView extends ListView {
private ListViewListener mListener;
public ExampleListView(Context context) {
super(context);
}
public ExampleListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExampleListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void requestLayout() {
super.requestLayout();
if (mListener != null) {
mListener.onChangeFinished();
}
}
public void setListener(ListViewListener listener) {
mListener = listener;
}
public interface ListViewListener {
void onChangeFinished();
}
}
并将侦听器设置为此ListView
ExampleListView listView = (ExampleListView) view.findViewById(R.id.practice_exercises_list);
listView.setListener(new ExampleListView.ListViewListener() {
@Override
public void onChangeFinished() {
txtCurrentFocus.requestFocus();
}
});