我正在使用Paging Library使用来从网络加载数据ItemKeyedDataSource。提取项目后,用户可以对其进行编辑,此更新在内存缓存内部完成(不使用任何数据库,例如Room)。
现在,由于PagedList本身无法更新(在此处讨论),我必须重新创建PagedList并将其传递给PagedListAdapter。
更新本身没有问题,但是在recyclerView使用new 更新之后PagedList,列表会跳至列表的开头,从而破坏先前的滚动位置。无论如何,要在保持滚动位置的同时更新PagedList(例如它如何与Room一起工作)?
数据源是通过以下方式实现的:
public class MentionKeyedDataSource extends ItemKeyedDataSource<Long, Mention> {
private Repository repository;
...
private List<Mention> cachedItems;
public MentionKeyedDataSource(Repository repository, ..., List<Mention> cachedItems){
super();
this.repository = repository;
this.teamId = teamId;
this.inboxId = inboxId;
this.filter = filter;
this.cachedItems = new ArrayList<>(cachedItems);
}
@Override
public void loadInitial(@NonNull LoadInitialParams<Long> params, final @NonNull ItemKeyedDataSource.LoadInitialCallback<Mention> callback) {
Observable.just(cachedItems)
.filter(() …Run Code Online (Sandbox Code Playgroud) android-adapter android-recyclerview android-architecture-components android-jetpack
我正在使用Paging Library从网络加载数据ItemKeyedDataSource.在获取项目后,用户可以编辑它们,此更新在内存缓存中完成(不使用像Room这样的数据库).
现在因为它PagedList本身无法更新(这里讨论),我必须重新创建PagedList并传递给它PagedListAdapter.
更新本身没有问题,但在recyclerView使用new 更新后PagedList,列表会跳转到列表的开头,从而破坏前一个滚动位置.无论如何更新PagedList同时保持滚动位置(就像它如何与Room一起工作)?
DataSource以这种方式实现:
public class MentionKeyedDataSource extends ItemKeyedDataSource<Long, Mention> {
private Repository repository;
...
private List<Mention> cachedItems;
public MentionKeyedDataSource(Repository repository, ..., List<Mention> cachedItems){
super();
this.repository = repository;
this.teamId = teamId;
this.inboxId = inboxId;
this.filter = filter;
this.cachedItems = new ArrayList<>(cachedItems);
}
@Override
public void loadInitial(@NonNull LoadInitialParams<Long> params, final @NonNull ItemKeyedDataSource.LoadInitialCallback<Mention> callback) {
Observable.just(cachedItems)
.filter(() …Run Code Online (Sandbox Code Playgroud) android-architecture-components android-jetpack android-paging android-architecture-paging
我正在尝试使用回收器视图并处理单击事件.我已经阅读了在回收站视图项上处理onClick事件的各种方法,例如:
所以我的第一个问题是哪个选项更好?我目前正在使用第一种方法,如果在视图持有者类中定义单击侦听器本身就是方法,那么如何使用适配器中的上下文,因为视图持有者类是静态的.
基本上,我想拥有一个静态视图持有者,并且在click事件上,打开一个我需要上下文的新Activity.
更新:添加适配器和ViewHolder代码.
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private Context mContext;
private List<Job> jobs;
public MyAdapter(Context context, List<Job> jobs) {
mContext = context;
this.jobs = jobs;
}
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View itemLayoutView = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.list_item, viewGroup, false);
itemLayoutView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext, MyActivity.class);
mContext.startActivity(intent);
}
});
return new ViewHolder(itemLayoutView);
}
@Override
public void onBindViewHolder(WorkExperienceAdapter.ViewHolder viewHolder, int i) {
//bindViewHolder code
} …Run Code Online (Sandbox Code Playgroud) 错误:任务“:app:processDebugManifest”执行失败。
com.android.manifmerger.ManifestMerger2$MergeFailureException: org.xml.sax.SAXParseException; 行号:1;列数:1;文件提前结束。