android-databinding

create different InverseBindingAdapter for Short and Integer values on android:text of EditText

人走茶凉 提交于 2019-12-12 04:55:28
问题 I create these methods for custom data binding @BindingAdapter("android:text") public static void setShortText(TextView view, short value) { view.setText(String.valueOf(value)); } @InverseBindingAdapter(attribute = "android:text") public static Short getShortText(TextView view) { try { return Short.parseShort(view.getText().toString()); } catch (NumberFormatException e) { return null; } } @BindingAdapter("android:text") public static void setIntText(TextView view, int value) { view.setText

How to use two-way data binding in Android for dynamically created fields

蓝咒 提交于 2019-12-12 03:55:54
问题 I have a form whose fields are set by server return. This is the code in the Activity. //returned by server String[] attributes = new String[] {"occupation", "salary", "age"}; LinearLayout dynamicLayout = (LinearLayout) findViewById(R.id.dynamic_layout); for (String attribute : attributes) { EditText text = new EditText(this); text.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT )); text.setText(attribute); dynamicLayout.addView(text); } I have this

Why is this custom view attribute ignored?

随声附和 提交于 2019-12-12 03:46:39
问题 I am trying to define an attribute for any view using the Data Binding Library, as explained in this Android Developers post. To do so, the post says one first needs a layout with an enclosing <layout> tag: <?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"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView

Two-way data-binding infinite loop

大城市里の小女人 提交于 2019-12-12 02:40:06
问题 I have a list of items. In each item's row I have 2 EditTexts side-by-side. EditText-2 depends on EditText-1's value. This list is bound with data-binding values in HashMap<String, ItemValues> For Example: Total _____1000____ Item A __1__ __200__ Item B __1__ __200__ Item C __1__ __200__ Item D __2__ __400__ First EditText is the share and the second value is its value calculated based on total and share. So, in example if I change any 1 share, all the values will be changed. So, shown in

Android : UI and data not survive when screen rotation in MVVM pattern

本秂侑毒 提交于 2019-12-11 18:04:05
问题 I try to implement MVVM by Mindorks to show data from here :(https://api.themoviedb.org/3/movie/384018?api_key=67bc513a7a353631119fdffe5f7377a8&language=en-US) in my Activity . I try using databinding for update UI, everything is going well untill I try to rotate my screen, I see from my logcat the data is always reload and my ImageView is always refresh, this is my Activity: public class DetailActivity extends BaseActivity<ActivityDetailBinding, DetailViewModel> implements DetailNavigator {

cannot find symbol method setUser_list_user_view(User_List_UserViewModel) though it is available in Binding Class

﹥>﹥吖頭↗ 提交于 2019-12-11 17:18:48
问题 While implementing MVVM architecture with Data Binding and Live Data run into problem with getting error "cannot find symbol method setUser_list_user_view(User_List_UserViewModel)" I have done many time rebuild, cleanup and other stuff but this error not going..I am doing this first time so not sure have implemented the right method. Below is my code. Thnx in advance for the help User_List_UserViewModel.java public class User_List_UserViewModel extends AndroidViewModel { private User_List

Data binding - access individual properties contained in LiveData

半世苍凉 提交于 2019-12-11 15:42:58
问题 Is there a way to do something like this with LiveData and data binding? ViewModel has this property: val weather: LiveData<UnitSpecificCurrentWeatherEntry> What I'm trying to do in the layout: <TextView android:id="@+id/textView" android:text="@{viewmodel.weather.value.someProperty}"... /> Is this possible in any way or do I have to split the object contained in LiveData into multiple ones for each property of the contained object? 回答1: From the point of view of MVVM pattern it's not

Are LiveData objects observable in XML?

删除回忆录丶 提交于 2019-12-11 15:37:50
问题 When I bind ObservableField<> objects to a view in XML, changes to the value via set() are immediately reflected in the view. When I bind LiveData<> objects in XML, however, the initial value is rendered but changes via value= have no effect on the view. They are passed to Kotlin observers. I assumed LiveData would work like Observable* classes in XML bindings. Is that not the case? If I need to observe a value in both XML and Kotlin, do I really need to create two observables? 回答1: You can

Weird DataBinding in Android

蹲街弑〆低调 提交于 2019-12-11 15:17:31
问题 I try to figure out how to work with data binding in Android and met a strange problem. When I put my ViewModel class in some package, generated ActivityMainBinding can't see it and say: error: package ViewModels does not exist . But if I put it in the root package, then trouble disappears. Is it my mistake or some kind of bug? Code: activity_main.xml <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http:/

Data Binding: ObservableField with lambda value doesn't compile

北城以北 提交于 2019-12-11 10:39:21
问题 I'm trying to define the visibility of the View by calculating the lambda that takes one parameter as an argument. I'm using Kotlin , btw. In my ViewModel I have: val customerPropVisibility: ObservableField<(KProperty1<Customer, *>) -> Int> = ObservableField( { _ -> // body of the lambda }) The binding expression for the View is the following: android:visibility="@{vm.customerPropVisibility.invoke(title)}" vm and title are properly declared as variables in the data tag of the layout. On