android-databinding

Data Binding onClick not working

六月ゝ 毕业季﹏ 提交于 2020-01-24 04:33:16
问题 I am getting started for using DataBinding and something is wrong with my onClick. GameViewModel.java public void onClickItem(int row, int col){ Log.d("click","row: "+row+" col: "+col); } @BindingAdapter("load_image") public static void loadImage(ImageView view,int imageId) { view.setImageResource(getDrawable(imageId)); } GameFragment.java @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //View view=inflater.inflate(R.layout

Data Binding for alternative layouts

爱⌒轻易说出口 提交于 2020-01-14 22:27:37
问题 I have faced with an issue with data binding for different layouts. I have layout file for different orientation. For portrait mode: <layout xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </layout> and for landspace mode: <layout

Android MVVM with Programmatic UI Customization

穿精又带淫゛_ 提交于 2020-01-14 14:39:47
问题 I'm trying to nail down proper MVVM layering in an app with the Android data binding lib. Really simple layouts, like in most examples, abstract nicely with XML layouts binding to methods in my View Model for event handling and model updates via observables. However, more often than not, there's UI customization that needs to be done programmatically (findViewById()...) and/or through things like injecting styling attributes into string resources. Should I just treat the Activity/Fragment as

Android- Cannot resolve symbol BaseObservable

倖福魔咒の 提交于 2020-01-14 10:45:49
问题 I am trying to implement data binding example in android and creating a POJO with bindable variables and i am getting this error ! please help. I am following this tutorial http://www.vogella.com/tutorials/AndroidDatabinding/article.html and here is my code import android.databinding.BaseObservable; import android.databinding.Bindable; public class TemperatureData extends BaseObservable { private String location; private String celsius; public TemperatureData(String location, String celsius)

Android Studio shows warning: Element merge is not allowed here

北慕城南 提交于 2020-01-13 07:50:35
问题 I create custom view based on LinearLayout. Class extends the LinearLayout class, in layout I have: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <merge> some staff here </merge> </layout> Android Studio shows the the warning Element merge is not allowed here , but app works. What's wrong? 回答1: I believe it's just a glitch in Android studio. Even the official documentation has merge as a direct child of layout : https://developer

How Do We Get Data Binding To Use Saved Instance State?

风格不统一 提交于 2020-01-12 02:21:55
问题 TL;DR: If a layout used with data binding has an EditText , and there is a binding expression for android:text , the binding expression overwrites the saved instance state value... even if we do not explicitly trigger a binding evaluation. What the user typed in before the configuration change gets wiped out. How do we work around this, so that on a configuration change, the saved instance state value is used? We have a silly Model : public class Model { public String getTitle() { return(

Data Binding: Cannot find symbol class BR

戏子无情 提交于 2020-01-11 02:06:10
问题 I try to use Data Binding in my existing project, but I can't get it to build. Using in Project build.gradle : dependencies { classpath 'com.android.tools.build:gradle:1.3.1' //Data Binding Beta classpath "com.android.databinding:dataBinder:1.0-rc4" classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7+' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } applying apply plugin: 'com.android.databinding' apply plugin: 'com

Android Data Binding two way binding with array

北城以北 提交于 2020-01-05 07:39:16
问题 I want to achieve two-way binding on a array with Data Binding in Android. This is a simplified version of the code I have: <data> <variable name="values" type="Integer[]" /> </data> <EditText ... android:text="@={Converter.toString(values[0])} /> But when I try to build this code I get a message as follows: cannot find method setTo(java.lang.Integer[], int, java.lang.Integer) in class android.databinding.ViewDataBinding How can I achieve two-way binding with an array, if at all possible? 回答1

Android Data Binding two way binding with array

天涯浪子 提交于 2020-01-05 07:39:09
问题 I want to achieve two-way binding on a array with Data Binding in Android. This is a simplified version of the code I have: <data> <variable name="values" type="Integer[]" /> </data> <EditText ... android:text="@={Converter.toString(values[0])} /> But when I try to build this code I get a message as follows: cannot find method setTo(java.lang.Integer[], int, java.lang.Integer) in class android.databinding.ViewDataBinding How can I achieve two-way binding with an array, if at all possible? 回答1

Error inflating class Fragment when testing fragment using DataBinding

安稳与你 提交于 2020-01-04 06:39:08
问题 Can someone help me on this? In my test I want to check if the login button is displayed on the StartPage. I've been struggling with this error for a while today and I don't know how it should be resolved.What am I missing here? Maybe this problem is somehow similar to this question: Espresso test fails with java.lang.String cannot be cast to com.abc.events.databinding.SponsorDetailBinding android.view.InflateException: Binary XML file line #6: Error inflating class fragment at android.view