我正在尝试使用Kotlin/Android数据绑定尝试将函数作为绑定适配器中的参数.此示例代码e: error: cannot generate view binders java.lang.StackOverflowError在构建时抛出,而日志中没有其他有用信息.
这是我的绑定适配器:
@JvmStatic
@BindingAdapter("onDelayedClick")
fun onDelayedClick(view: View, function: () -> Unit) {
// TODO: Do something
}
Run Code Online (Sandbox Code Playgroud)
XML:
<View
android:id="@+id/test_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:onDelayedClick="@{() -> viewModel.testFunction()}"/>
Run Code Online (Sandbox Code Playgroud)
我的ViewModel中的方法和方法:
fun testFunction() = Unit
Run Code Online (Sandbox Code Playgroud)
我一直在努力解决这个问题,而且我尝试过的任何工作都没有,所以任何帮助都会受到赞赏.
我想在使用 DownloadManager 单击按钮时更新应用程序的 sqlite 数据库。
但它说“java.lang.IllegalArgumentException:不是文件URI:/data/user/0/com.example.laudien.listviewtesting/databases/Employees”
我做错了什么?我需要许可吗?互联网权限已在清单中。
这是我的 updateDb() 方法的代码:
private void updateDb() {
DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); // create download manager
DownloadFinishedReceiver receiver = new DownloadFinishedReceiver(); // create broadcast receiver
registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); // register the receiver
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(DATABASE_URL)); // create a download request
// delete database file if it exists
File databaseFile = new File(getDatabasePath(DATABASE_NAME).getAbsolutePath());
if(databaseFile.exists())
databaseFile.delete();
request//.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN) // not visible
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI) // only via wifi
.setDestinationUri(Uri.parse("file:" + getDatabasePath(DATABASE_NAME).getAbsolutePath())); // set path in app …Run Code Online (Sandbox Code Playgroud)