android-databinding

Detecting onClick in recycler view using data binding in android

为君一笑 提交于 2019-12-10 02:48:58
问题 I am Referring to vogella-tutorial for databinding What i am trying to do : What is the best way to detect onClick in recycler view row for each Item using the dataBinding activity_second.xml <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="temp" type="com.vogella.android.databinding.TemperatureData" /> <variable name="presenter" type="com.vogella.android.databinding.MainActivityPresenter"/> </data> <android

DataBinding: How to use BaseActivity / How to use Abstraction

主宰稳场 提交于 2019-12-10 02:34:47
问题 I am trying to add DataBinding to my app. In my app, I have a BaseActivity which has a Toolbar and a FrameLayout. FrameLayout is container for activities' which extend the BaseActivity. How can I add databinding to both my BaseActivity and the extending activities? I'll share my code without DataBinding: Here is my BaseActivity.java : public class BaseActivity extends AppCompatActivity { @Override public void setContentView(@LayoutRes int layoutResID) { LinearLayout container = (LinearLayout)

Using a BindingAdapter with a string-array from the resources

≯℡__Kan透↙ 提交于 2019-12-10 02:09:56
问题 I have an almost simple idea: I want to generate an Adapter for a spinner with the data binding API and an BindingAdapter. Here is the XML I want to use: <Spinner android:id="@+id/country" android:layout_width="wrap_content" android:layout_height="wrap_content" app:value="@{address.country}" app:data="@{@array/countries}" app:keys="@{@array/iso_3166_2}"/> Address here is a simple class which has a field called country which is a String and will contain a ISO-3166-2 String. To keep it simple

How to bind a layout_width and layout_height using data binding in Android

让人想犯罪 __ 提交于 2019-12-09 16:26:21
问题 I'm trying to bind a boolean that indicates to an ImageView if the screen size is small, so it shrinks if I need more space for other components. I'm using the DataBinding Library to do so. My layout whose width and height depends on this boolean: ... <data> ... <variable name="smallScreen" type="boolean"/> ... </data> ... <ImageView android:layout_width="@{smallScreen ? @dimen/img_small_screen_size : @dimen/img_big_screen_size}" android:layout_height="@{smallScreen ? @dimen/img_small_screen

Android include layout dynamically with data-binding library

我只是一个虾纸丫 提交于 2019-12-09 14:52:20
问题 I'm using MVVM framework for Android application with data-binding library. I have some reusable compoments, that should have every activity. f.e. toolbar, menu, floating action button. I want to create a generic activity, that will implement all these reusable features and then every activity class will be inherited from this generic activity. I also have GenericViewModel class and every other ViewModel is inherited from this generic class. But I have a problem with layout. I want to create

How to set Android DataBinding in nested layouts

旧街凉风 提交于 2019-12-09 10:56:41
问题 I was just reading about data binding feature in android. I was trying to bind a view from a nested layout. My activity is android's default template of DrawerMenuActivity and it has content_my_activity layout nested inside activity_my_activity layout. I have 3 auto generated binding classes. MyActivityBinding , AppBarMyActivityBinding and ContentMyActivityBinding . I tried initialising all 3 class as below: MyActivity.java MyActivityBinding activityBinding; AppBarMyActivityBinding

Android data binding “Missing import expression although it is registered” after upgrade to gradle 5.0

冷暖自知 提交于 2019-12-09 07:36:04
问题 After I upgrade my Android studio to 3.4, Android Gradle Plugin to 3.4 and gradle to 5.1.1 I got the data binding errors like below I have made sure I cleaned project and rebuild, I have cleared cache and restarted AS. This issue never happened before the upgrade I can confirm it is because of the new gradle update DataBinderMapperImpl.java:54: error: cannot find symbol e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors. ****/ data

Android Databinding in Sub-module

◇◆丶佛笑我妖孽 提交于 2019-12-09 07:30:38
问题 I have an application module, let's say "Test". The "Test" module depends on a sub-module B. Both enable databinding. In library module B, I create a simple activity using databinding, its purpose is for reusability, for example: I can create a base Login screen and use it in many apps later. Below is sample code in Package B. package com.test.packageb open class MainActivity : AppCompatActivity() { lateinit var binding : ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?)

Cannot find the setter for attribute with parameter

大兔子大兔子 提交于 2019-12-09 03:30:30
问题 I am working on DataBinding with BindingAdapter . Here is my custom method. @BindingAdapter("{bind:fadevisible}") public static void setFadeVisible(LinearLayout view, int visible) { Log.e("Bindings", "setFadeVisible: "); } And in xml file i am calling it like <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" app:fadevisible="@{1}"/> But it is showing error Error:Execution failed for task ':app:compileDebugJavaWithJavac'. java

Android Data binding - Error:(119, 29) Identifiers must have user defined types from the XML file. main_radio_subscribe is missing it

不打扰是莪最后的温柔 提交于 2019-12-09 02:20:16
问题 I been trying to control the visibility of a view using the Implicit Attribute Listeners(reference) in android data binding which allows to access views by id and access attributes like checked, visible etc ..., however when trying to use this, it throws an error like so Error:(119, 29) Identifiers must have user defined types from the XML file. addTodo_switch_remind is missing it <android.support.v7.widget.SwitchCompat android:id="@+id/addTodo_switch_remind" style="@style/MediumTextViewStyle