android-databinding

Kotlin DataBinding pass static function into layout xml

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 17:03:10
问题 In Java, i can easily pass static function to layout xml using: public static String formatUnixTime(long timeInSeconds, String pattern) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, Locale.US); String value = simpleDateFormat.format(new Date(timeInSeconds * 1000)); return value; } in xml: android:text='@{Utils.formatUnixTime(model.start_time, "hh:mm:ss")}' But i tried in Kotlin with companion but no luck. It said error: cannot find symbol import my.package.name

Android Why use executePendingBindings in RecyclerView

假装没事ソ 提交于 2019-12-10 16:46:59
问题 I have been using lately data bindings and i came across the executePendingBindings method. The documentation shows little much about it and i can't understand how it works or when to use it. A lot of developers use the executePendingBindings inside the onBindViewHolder callback but i don't see any differences myself in recycler when using it or not. Can someone explain why its important to use in recycler?? Thanks @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder,

Why does using the Binding Interface resut in a ClassNotFound exception?

狂风中的少年 提交于 2019-12-10 15:28:56
问题 I am trying to create a custom attribute for any Android View . I saw in this post that I could do it with the Data Binding Library. The Data Binding Guide and the post explain the layout should begin with a <layout> tag, but when inflating it I get the following exception: 05-06 22:36:31.294 11916-11916/com.plnech.example E/AndroidRuntime: FATAL EXCEPTION: main Process: com.plnech.example, PID: 11916 android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error

Float Label hint (TextInputLayout) not works with Android Data Binding

梦想的初衷 提交于 2019-12-10 12:56:21
问题 I need create fields edit page in app. There are list of EditText for edit Contact. For each field type i have an layout. As example - for name and last name it is float labeled edit text. For facebook - simple edit text with icon. I am creating this list with Android Data Binding Library I've created layout <data> <variable name="item" type="app.core.db.model.Field" /> </data> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android

Getting Date from getTimeInMillis when using Databinding

强颜欢笑 提交于 2019-12-10 12:55:04
问题 I have a timeInMillis value, which I know I can get a Date from with something like; SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); String dateString = formatter.format(new Date(dateInMillis))); I'm using DataBinding to populate a RecyclerView . I am also aware that I can manipulate strings when using DataBinding with something like this; android:text='@{String.format("%.1f", example.double)}' However, I cannot work out how to populate the TextView with a formatted Date from

Android Data Binding and Kotlin

泄露秘密 提交于 2019-12-10 12:39:52
问题 I am converting my Android application from Java to Kotlin. It is working fine, except when I try to convert a file that is using Android Data Binding Library. In that case, Android Studio complains at compile time about unresolved reference: Error:(10, 44) Unresolved reference: AdapterHistoriesListBinding Where AdapterHistoriesListBinding is the name of a file that should be generated by the Data Binding Library. It was working correctly in Java, so I guess it is an issue with Kotlin. I am

Is it possible to redefine a library's databinding resource?

别说谁变了你拦得住时间么 提交于 2019-12-10 11:14:17
问题 I am developing a library that uses Data Binding to process attributes in a Layout 's Views (I won't develop as it is irrelevant to this issue). As the applications should be able to specify their own layout, I am trying to leverage the resource prioritization mechanism: In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library module is not compiled into

how to import public static field from class in android data binding

。_饼干妹妹 提交于 2019-12-10 11:07:45
问题 I want to import some string from interface constant in android layout data binding. Gradle build fails if i use this line android:drawableRight="@{item.icon.equalsIgnoreCase(Constants.FOOD_TYPE_NON_VEG)? @drawable/ic_nonveg : @drawable/ic_veg}" But below line works android:drawableRight="@{item.icon.equalsIgnoreCase(`nonveg`)? @drawable/ic_nonveg : @drawable/ic_veg}" Sample xml is <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data

Applying databinding adapter to include tag

落爺英雄遲暮 提交于 2019-12-10 10:37:33
问题 I'm using databinding in my project and I have one for setting a visibility condition from the viewmodel: <View app:visibilityCondition="@{viewModel.showingItems}" /> This all works fine, but suddenly when I want to use it on an include tag like this: <include layout="@layout/my_include_layout app:visibilityCondition="@{viewModel.showingItems}" /> It doesn't build, with the following error: e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding

Passing string to included layout via data binding not working

泄露秘密 提交于 2019-12-10 10:05:20
问题 I am trying to pass a simple string to an layout from my main layout using the Android data binding feature. It compiles fine, but the value being passed to the include is not actually being passed. i.e. - it does not show up in my layout. <?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="mytitle" type="java.lang