Kotlin-android: unresolved reference databinding

后端 未结 16 1106
借酒劲吻你
借酒劲吻你 2020-12-02 16:23

I have following fragment class written in Java using the new databinding library

import com.example.app.databinding.FragmentDataBdinding;

public class Data         


        
16条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 16:58

    Add Databinding in android Project using when you have use kotlin language.

    Below steps

    --First you need to add the below plugin

    **apply plugin: 'kotlin-kapt'**
    

    --Second dataBinding enabled true

    **dataBinding {
            enabled = true
        }**
    

    All this point added in app.build.gradle after hit "SYNC NOW"

    Lets For example you have edit profile activity then how to define binding variable in kotlin??

    lateinit var buildProfileBinding: ActivityBuildProfileBinding
    
    buildProfileBinding = getBinding()
    

    Here,get binding is method to handle which type of binding object

    protected  T getBinding() {
                    return (T) binding;
                }
    

提交回复
热议问题