简体   繁体   English

如何将项目滚动到列表Android的顶部?

[英]How to scroll an item to the top of the list android?

i get a jsonArray from server and show its data in an arraylist. 我从服务器获取一个jsonArray,并在arraylist中显示其数据。 any jsonObject have a status field. 任何jsonObject都有一个状态字段。 i want to check if status is "S" this jsonObject scroll to the top of the list. 我想检查状态是否为“ S”,此jsonObject滚动到列表顶部。 for example 3 jsonobject status is "S",i want to scroll this three item to the top of the list and another jsonobject which have status "R" below this three item. 例如3 jsonobject状态为“ S”,我想将这三个项目滚动到列表的顶部,并将另一个jsonobject的状态滚动为“ R”在这三个项目下面。

IF you are using Recyclerview than use 如果您使用Recyclerview而不是

layoutmanager.scrollToPosition(int position);

If you use Listview 如果您使用Listview

listview.setSelection(int position);

If you are usin a listview, try 如果您使用的是列表视图,请尝试

listView.setSelectionAfterHeaderView();

Or 要么

list.smoothScrollToPosition(0);

with 0 for the first item or another index of an item if you have it. 第一项为0,如果有,则为另一个索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM