Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
alexacm2
architecture-components-samples
提交
f65b3a8a
A
architecture-components-samples
项目概览
alexacm2
/
architecture-components-samples
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
architecture-components-samples
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f65b3a8a
编写于
10月 29, 2019
作者:
D
Dustin Lam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a workaround for initial load offset issue
上级
0749e931
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
11 addition
and
1 deletion
+11
-1
PagingWithNetworkSample/app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/ui/RedditActivity.kt
...mple/paging/pagingwithnetwork/reddit/ui/RedditActivity.kt
+11
-1
未找到文件。
PagingWithNetworkSample/app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/ui/RedditActivity.kt
浏览文件 @
f65b3a8a
...
@@ -27,6 +27,8 @@ import androidx.lifecycle.Observer
...
@@ -27,6 +27,8 @@ import androidx.lifecycle.Observer
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.ViewModelProvider
import
androidx.lifecycle.ViewModelProvider
import
androidx.paging.PagedList
import
androidx.paging.PagedList
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
com.android.example.paging.pagingwithnetwork.GlideApp
import
com.android.example.paging.pagingwithnetwork.GlideApp
import
com.android.example.paging.pagingwithnetwork.R
import
com.android.example.paging.pagingwithnetwork.R
import
com.android.example.paging.pagingwithnetwork.reddit.ServiceLocator
import
com.android.example.paging.pagingwithnetwork.reddit.ServiceLocator
...
@@ -82,7 +84,15 @@ class RedditActivity : AppCompatActivity() {
...
@@ -82,7 +84,15 @@ class RedditActivity : AppCompatActivity() {
}
}
list
.
adapter
=
adapter
list
.
adapter
=
adapter
model
.
posts
.
observe
(
this
,
Observer
<
PagedList
<
RedditPost
>>
{
model
.
posts
.
observe
(
this
,
Observer
<
PagedList
<
RedditPost
>>
{
adapter
.
submitList
(
it
)
adapter
.
submitList
(
it
)
{
// Workaround for an issue where RecyclerView incorrectly uses the loading / spinner
// item added to the end of the list as an anchor during initial load.
val
layoutManager
=
(
list
.
layoutManager
as
LinearLayoutManager
)
val
position
=
layoutManager
.
findFirstCompletelyVisibleItemPosition
()
if
(
position
!=
RecyclerView
.
NO_POSITION
)
{
list
.
scrollToPosition
(
position
)
}
}
})
})
model
.
networkState
.
observe
(
this
,
Observer
{
model
.
networkState
.
observe
(
this
,
Observer
{
adapter
.
setNetworkState
(
it
)
adapter
.
setNetworkState
(
it
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录