我需要一些有关夏洛克列表导航的帮助。目标:当您打开导航时,我想滚动到顶部/焦点到第一行,因此第一项始终可见。问题:现在当列表有更多项目作为屏幕可以显示时(通常在横向模式下),当我选择即第 4 个项目然后打开列表时,第一个项目不可见,它集中在最后一个选定的项目上。它适用于我在自定义微调器中使用下面的代码,但是当我尝试在 IcsSpinner 中覆盖相同的方法时它没有工作。
代码:
/**
* Cusrom 微调器类 - 打开时始终关注第一项 * */ 类 CustomSpinnerSelection 扩展 Spinner {
private boolean mToggleFlag = true;
//some constructors here
@Override
public int getSelectedItemPosition() {
// this toggle is required because this method will get called in other
// places too, the most important being called for the
// OnItemSelectedListener
if (!mToggleFlag) {
return 0; // get us to the first element
}
return super.getSelectedItemPosition();
}
@Override
public boolean performClick() {
// this method shows the list of elements from which to select one.
// we have to make the getSelectedItemPosition to return 0 so you can
// fool the Spinner and let it think that the selected item is the first
// element
mToggleFlag = false;
boolean result = super.performClick();
mToggleFlag = true;
return result;
}
}