android-databinding

Can you use a BindingAdapter on a ViewStub?

 ̄綄美尐妖づ 提交于 2021-01-28 08:08:37
问题 I want to create an "inflateWhen" BindingAdapter and attach it to a viewstub to have it inflate when a boolean value is true. However, the BindingAdapter keeps trying to operate on the root view of the viewstub, causing it to fail to compile. Is there any way to do this as a bindingadapter rather than having to do it programmatically in the activity? Here's what I have so far: @BindingAdapter("inflateWhen") fun inflateWhen(viewstub: ViewStub, inflate: Boolean) { if (inflate) { viewstub

What's the need to call DataBindingUtil.setContentView() when using Data Binding Library?

你。 提交于 2021-01-28 05:52:37
问题 I am learning to use Data Binding Library. I came to know that it removes the need to call findViewById() manually and makes the code more robust and readable. To understand the use, I did the following: made a temp_layout.xml which contains 2 text views with ids 'tv1' and 'tv2' added the <layout> tag as root clicked on 'build project' Now I found that a new 'TempLayoutBinding' class was available which contained the variables 'tv1' and 'tv2'. My question is that , even when I already

Access Binding Adapters in multi module project

北战南征 提交于 2021-01-27 19:41:56
问题 I've got a multi module project where the app module contains my binding adapters and my feature module depends on my app module since it is a dynamic feature module. App (contains binding adapters) ----> Dynamic feature module (where the layout is present) I have databinding and kapt enabled in all the modules. I'm unable to build the app successfully. Android Studio gives me the following error, error: cannot find symbol import com.app.module1.databinding.FeatureItemBindingImpl; Layout file

Access Binding Adapters in multi module project

一世执手 提交于 2021-01-27 19:16:00
问题 I've got a multi module project where the app module contains my binding adapters and my feature module depends on my app module since it is a dynamic feature module. App (contains binding adapters) ----> Dynamic feature module (where the layout is present) I have databinding and kapt enabled in all the modules. I'm unable to build the app successfully. Android Studio gives me the following error, error: cannot find symbol import com.app.module1.databinding.FeatureItemBindingImpl; Layout file

Databinding not work together with viewbinding in Kotlin

若如初见. 提交于 2021-01-27 07:01:51
问题 Android Studio 3.6 build.gradle: buildscript { ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.6.0-beta01' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" in app/build.gradle: android { viewBinding.enabled = true dataBinding { enabled = true } in my activity: import android.os.Bundle import android.util.Log import androidx.appcompat.app.AppCompatActivity import androidx.viewpager2.widget

How can I pass multiple arguments via xml for a custom setter when using Android data binding

本秂侑毒 提交于 2021-01-27 02:58:20
问题 Suppose I have a custom setter method where I need two arguments: @BindingAdapter({"imageUrl", "placeholder"}) public static void loadImage(ImageView imageView, String imageUrl, Drawable drawable) { Picasso.with(imageView.getContext()).load(imageUrl).placeholder(drawable).into(imageView); } What would the corresponding xml look like? 回答1: Looks like it can be done like this: <ImageView app:imageUrl=“@{data.imageUrl}” app:placeholder=“@{@drawable/placeholder}”/> see http://developer.android

How can I pass multiple arguments via xml for a custom setter when using Android data binding

戏子无情 提交于 2021-01-27 02:56:45
问题 Suppose I have a custom setter method where I need two arguments: @BindingAdapter({"imageUrl", "placeholder"}) public static void loadImage(ImageView imageView, String imageUrl, Drawable drawable) { Picasso.with(imageView.getContext()).load(imageUrl).placeholder(drawable).into(imageView); } What would the corresponding xml look like? 回答1: Looks like it can be done like this: <ImageView app:imageUrl=“@{data.imageUrl}” app:placeholder=“@{@drawable/placeholder}”/> see http://developer.android

How to set click listener and pass edittext fields value to view model using data binding

喜夏-厌秋 提交于 2021-01-21 07:24:11
问题 Hi I am trying to use data binding and mvvm architecture in my android app. I want to add click listener using data binding in the layout and send the values of username and password edittext to the view model and it will execute the web service and call appropriate method of LoginActivity like startHomeActivity() . Does anyone know how to do this or Am I taking wrong approach ? I have below snippet of code of my activity, layout and view model LoginActivity.kt class LoginActivity :

How can I use Data Binding with ProgressBar?

丶灬走出姿态 提交于 2021-01-04 07:49:52
问题 I'm trying to use DataBinding for a ProgressBar , but I didn't know how this is my xml code <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="addActivity" type="com.khairo.dallasadmin.view.addScreenSaver.AddScreenSaver" /> <variable name="saverModel" type="com.khairo.dallasadmin.model.addScreenSaver

How can I use Data Binding with ProgressBar?

偶尔善良 提交于 2021-01-04 07:49:49
问题 I'm trying to use DataBinding for a ProgressBar , but I didn't know how this is my xml code <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="addActivity" type="com.khairo.dallasadmin.view.addScreenSaver.AddScreenSaver" /> <variable name="saverModel" type="com.khairo.dallasadmin.model.addScreenSaver