android - 如何在不滚动的情况下直接降落在特定位置?
问题描述
如何在列表视图中打开特定位置?让我告诉我我的要求和我尝试了什么!这是目录,当我们在第 100 页时,当我们单击目录时,它通过突出显示显示第 100 页。这是要求。但在我的情况下,它一直在滚动,用户需要等到滚动在第 100 页停止。我使用了 setSelection 但它不起作用。因此,如果我使用 smoothScrollingToPosition ,它会继续滚动以停止在特定位置。所以我的要求是不直接滚动以打开特定页面。下面是逻辑。我在类适配器的构造函数中应用了列表视图。
在适配器中,
@Override
public final View getView(final int position, View convertView, final ViewGroup parent) {
int type = getItemViewType(position);
if ((convertView == null) || (((Integer) convertView.getTag()) != type)) {
convertView = createView(position);
convertView.setTag(type);
}
final BaseTableOfContents node = getItem(position);
for(int i=0; i<mNodes.size();i++){
BaseTableOfContents nodes = mNodes.get(i);
if(okayToHighlightAnchorNode(nodes,i)==true){ //only when true, it lands to specific position.
Log.v("nodes","nodes"+okayToHighlightAnchorNode(nodes,i) + nodes.getText() + i);
// returnValue.getListView().setSelection(i); //but this is not working.
returnValue.getListView().smoothScrollToPosition(i,i); //this keeps on scrolling to specific page instead of directly landing to the specific page.
}
}
解决方案
对于直接滚动,请使用以下代码:
getListView().setSelection(21);// anylistview.setSelection(21);
为了平滑滚动,请使用:
getListView().smoothScrollToPosition(21);//anylistview.smoothScrollToPosition(21);
推荐阅读
- r - 根据行中特定值的存在替换行中的值
- angular - primeng 的多选组件中的事件顺序
- mysql - 如何使用触发器更改格式?
- sql - 计算每行的平均值,然后计算每列的平均值
- python - Pandas CSV KeyError
- python - XlsxWriter 图表系列直接来自没有工作表参考的数据
- html - 如何在 Excel VBA 中单击“创建问题”按钮
- arrays - 如何将所有 id 从 json 获取到其他变量的数组 - jmeter
- r - 在单个 ggrepel 标签中对齐文本行
- r - 半连续变量是 lp_solve 独有的还是其他 MILP 优化器有它们?