我有一个类似聊天的活动,我使用带有PagedListAdaper的RecyclerView来加载一堆消息.我正在使用PositionalDataSource来加载数据.加载它的自我工作正常但是当我发送消息时,我使我的数据源无效并且列表被重新制作.我的问题是,当它这样做时它会闪烁:

我尝试添加setHasStableIds(true)并重写getItemId,它可以在一个简单的适配器上工作,但它似乎在这里不起作用.我似乎也无法将项添加到getCurrentList(),因为它不受支持.此外,我没有使用数据库,只是向服务器发出请求.
所以我的问题是,除了使数据源失效之外,还有更好的方法吗?有没有办法阻止列表在发送消息时闪烁?或者这个图书馆不适合我的聊天活动?
编辑:
我的差异回调
private val DIFF_CALLBACK: DiffCallback<MessageModel> = object : DiffCallback<MessageModel>() {
override fun areItemsTheSame(@NonNull oldMessage: MessageModel, @NonNull newMessage: MessageModel) =
oldMessage.id == newMessage.id
override fun areContentsTheSame(@NonNull oldMessage: MessageModel, @NonNull newMessage: MessageModel) =
oldMessage.equals(newMessage)
}
Run Code Online (Sandbox Code Playgroud)
Edit2我修复了它:
所以我设法通过使用PagedListAdapterHelper并在加载项目后设置它的列表来修复它:
private var mHelper: PagedListAdapterHelper<MessageModel>? = null
init {
mHelper = PagedListAdapterHelper(this, DIFF_CALLBACK)
setHasStableIds(true)
}
fun setList(pagedList: PagedList<MessageModel>) {
pagedList.addWeakCallback(pagedList.snapshot(), object:PagedList.Callback() {
override fun onChanged(position: Int, count: Int) {
}
override fun onInserted(position: Int, count: Int) {
mHelper?.setList(pagedList) …Run Code Online (Sandbox Code Playgroud) 使用Android架构的导航组件,我有以下导航图
-> [Home] -> [Articles List] -> [Specific Article]
我也有一个深层链接[Specific Article].当它打开时,当前导航到[Home].
我想合成一个背板,这样导航就可以回到[Articles List]([Home]如果再次导航的话).
这样做的导航方式是什么?
android android-architecture-components android-architecture-navigation
我们注意到AlarmManagerCompat,由于AlarmManager不同版本的操作系统中的行为不同,仅在我们的应用程序中实现警报/提醒功能并不是一种可靠的方法.(例如,打盹模式)
最初,我们计划使用Evernote的android-job库来帮助我们在应用程序中实现警报/提醒功能.
但是,在此过程中,我们也注意到谷歌刚刚发布WorkerManager.
到目前为止,WorkerManager当我们在应用程序退出后运行一些一次性后台作业(几乎是即时的,具有互联网连接约束)时,对我们来说效果很好.
我们计划使用WorkerManager实现警报/提醒功能.
我想知道,WorkerManager实现这样的功能有多可靠?有人尝试过吗?我们的目标是API 15及更高版本.
我试图在新的导航组件中找到一个方法,但我没有找到任何相关的方法.
我目前的目的地是:
mainHostFragment.findNavController().currentDestination
Run Code Online (Sandbox Code Playgroud)
但我无法获得任何对显示片段的引用.
android android-fragments kotlin android-architecture-components android-architecture-navigation
我使用Paging Library来分页我的数据集.我要做的是刷新RecyclerView我的数据库中的后数据已被更改.
我有这个LiveData:
val listItems: LiveData<PagedList<Snapshot>> = object : LivePagedListProvider<Long, Snapshot>() {
override fun createDataSource() = SnapshotsDataSource()
}.create(null, PagedList.Config.Builder()
.setPageSize(PAGE_SIZE)
.setInitialLoadSizeHint(PAGE_SIZE)
.setEnablePlaceholders(false)
.build()
)
Run Code Online (Sandbox Code Playgroud)
而且DataSource:
class SnapshotsDataSource : KeyedDataSource<Long, Snapshot>(), KodeinGlobalAware {
val db: FirebaseDb = instance()
override fun getKey(item: Snapshot): Long = item.timestamp
override fun loadInitial(pageSize: Int): List<Snapshot> {
val result = db.getSnapshotsTail(pageSize)
return result
}
override fun loadAfter(key: Long, pageSize: Int): List<Snapshot> {
val result = db.getSnapshotsTail(key, pageSize)
return result.subList(1, …Run Code Online (Sandbox Code Playgroud) pagination android android-architecture-components android-paging
在使用android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01目标和编译sdk 27 将NavigationComponent()集成到我的项目中后使用proguard时遇到此崩溃
2018-05-16 12:13:14.044 24573-24573/com.mypackage.myapp.x E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mypackage.myapp.x, PID: 24573
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myapp.x/com.mypackage.myapp.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
Caused …Run Code Online (Sandbox Code Playgroud) android android-proguard android-jetpack android-architecture-navigation
Android studio 3.2 canary 14没有渲染导航标签.它只是显示等待构建完成.
navigation_graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment
android:id="@+id/fragment_nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation_graph" />
</navigation>
Run Code Online (Sandbox Code Playgroud)
android android-studio android-navigation android-architecture-components android-architecture-navigation
是否可以在两个(或更多)容器之间共享导航图?我想要实现的是拥有两个容器(NavHosts):
我想有一个导航图,因为来自一个容器的片段可以触发来自其他容器的操作.否则它(具有相互交互的更多导航图)将变得不整齐,并且库创建的问题将超越优势.
android android-architecture-components android-architecture-navigation
我有一个Android待办事项列表应用程序,使用Room访问SQLite数据库.然后我想在导航抽屉中列出可用列表.所以我使用了Paging Library.现在RecyclerView是空的,我不知道为什么.顺便说一句:我的名单都没有.我是初学者,所以我坚持官方教程.我已经发现,他们错了,ViewModel需要一个空的构造函数.现在的情况如下:设置适配器的方法成功调用(8),ViewModel创建(7)Adapter创建(1),setList()方法调用(9),但没有Holder创建(4),没有onCreateViewHolder或被onBindViewHolder调用(2,3),没有DiffCalback调用任何方法(5,6),只显示一个空的Recycler视图.该PagedList<SQLList>包含正确的信息,但没有信息被传递给适配器.有谁知道为什么?//对不起我的英语不好.
适配器类:
//this is my Adapter. SQLList is my object (Equivalent to the User object in
the tutorial)
public class ListsAdapter extends PagedListAdapter<SQLList,ListsAdapter.Holder> {
private Context context;
public ListsAdapter(Context context) {
//1
super(DIFF_CALLBACK);
this.context = context;
}
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//2
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.list_item,null);
return new Holder(view);
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我正在使用目前处于alpha状态的新导航控制器.它工作正常,但我找不到任何文档或示例应用程序,以了解如何进行测试.谷歌也发布了android.arch.navigation:navigation-testing用于测试导航的库,但同样没有文档.
任何帮助或建议将不胜感激.
android android-testing android-jetpack android-architecture-navigation
android ×10
android-architecture-components ×7
android-architecture-navigation ×6
android-room ×1
kotlin ×1
pagination ×1