gpt4 book ai didi

android - 在 Android 中使用 Pull to refresh 刷新 Listview 后获取添加的新项目

转载 作者:行者123 更新时间:2023-11-29 15:57:10 25 4
gpt4 key购买 nike

我有一个带有下拉刷新功能的 ListView。刷新 ListView 后,它移动到顶部。但我想显示新添加到 ListView 的项目。如何实现它,任何人都可以帮助我。提前致谢。

最佳答案

使用此属性 android:stackFromBottom="true",因为它总是在 ListView 的底部添加新项目。就像下面的代码,

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:divider="@null"
android:stackFromBottom="true" >
</ListView>

然后在你的代码中再添加一件事,

[listView].smoothScrollToPosition([adapter].getCount() - 1);

关于android - 在 Android 中使用 Pull to refresh 刷新 Listview 后获取添加的新项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27398142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com