当我构建项目时.我在app上遇到错误:visibleGone
我还在build.gradle中启用了dataBinding并使用了android架构组件和mvvm.项目targetSdkVersion是 26和support lib version is 26.0.1.
以下是错误消息
error: package com.****.****.databinding does not exist
error: cannot find symbol class ActivityMainBinding
Cannot find the setter for attribute 'app:visibleGone' with parameter type boolean on android.widget.Button.
Run Code Online (Sandbox Code Playgroud)
这是我的activity_main.xml
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="loading"
type="boolean" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.aungmyolwin.importdb.MainActivity">
<Button
android:id="@+id/btn_load_sql"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load from SQL"
app:visibleGone="@{!loading}"/>
<Button
android:id="@+id/btn_load_room"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load from Room mapper"
app:visibleGone="@{!loading}"/>
<TextView
android:id="@+id/tv_import_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Importing database...."
app:visibleGone="@{loading}"/> …Run Code Online (Sandbox Code Playgroud) 让我从示例代码片段开始
suspend fun executeLive(result: MutableLiveData<Person>) {
val response = ... //suspend api request
mediatorLiveData.removeSource(response)
mediatorLiveData.addSource(response) {
result.value = sortData(it) // sortData is also suspend function which sortData at Dispatcher.Default
}
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,sortData不能调用lambda function(在这种情况下addSource)。而且我已经声明executeLive为suspend,这就是为什么suspendapi 请求可以首先启动。但是sortData函数显示编译时错误
挂起函数只能从协程主体调用
那么我该如何改变我的代码结构来解决这个问题呢?
更新:有没有关于这个的文章?
实际上,我是Paging Library的新手.这是一种情况,我正在从我的ViewModel观察PagedList,即使新闻列表出现在UI上也总是返回零.
viewModel.getNews().observe(this, news -> {
swipeRefreshLayout.setRefreshing(false);
Timber.d("news size is %s",news.size());// **news size is 0**
adapter.submitList(news);
});
Run Code Online (Sandbox Code Playgroud)
我的DataSource是
public class NewsDataSource extends ItemKeyedDataSource<String, News> {
private MutableLiveData<Resource.Status> netStatusLive = new MutableLiveData<>();
/*Hide Logic for clean purpose*/
private List<News> localNewsList = new ArrayList<>();
public NewsDataSource( /*Hide Logic for clean purpose*/) {
/*Hide Logic for clean purpose*/
}
@Override
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<News> callback) {
netStatusLive.postValue(Resource.Status.LOADING);
localNewsList.clear();
Disposable disposable = /*Hide Logic for …Run Code Online (Sandbox Code Playgroud) android android-architecture-components android-jetpack android-paging
我是RecyclerView选择库的新手。我准备RecyclerView选择多个项目,只需单击一下即可。我的问题是所有文章和教程都表明选择过程始于长按。
如何覆盖以单击即可开始选择?谢谢。
我正在使用 implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'
本教程,我尝试过..
我正在尝试为我的协程创建惰性函数。我创建了这样的 util 函数。
fun <T> lazyCoroutine(scope: CoroutineScope, block: suspend CoroutineScope.() -> T): Lazy<T> {
val some = scope.async(start = CoroutineStart.LAZY) {
block.invoke(this)
}
return lazy {
some.await()
}
}
Run Code Online (Sandbox Code Playgroud)
但在终端显示
我也不想回来Deferred<T>,我只想回来刚出来的deferred。我看到大部分文章返回的内容Deferred<T>与我的场景不符。有没有相关的解决办法请指点一下。祝你有美好的一天!。