【问题标题】:Data Binding in AndroidAndroid中的数据绑定
【发布时间】:2020-11-12 06:06:52
【问题描述】:

我知道这不是什么新问题,但因为我需要在 java(generated) 包中添加数据绑定,而且我之前在任何以前的项目中都没有使用过它,所以我可以在互联网上看到是将这个添加到我在android中的应用级build.gradle文件中。

      dataBinding {
      enabled = true
      }

但它不起作用,我得到的错误是

[databinding] {"msg":"No class attribute for \u0027view\u0027 node","file":"C:\\Users\\pc\\Desktop\\Astrotell Project\\AstrotellUserApp\\app\\src\\main\\res\\layout\\fragment_resetpassword.xml","pos":[]}

我不明白这个的意思,我的fragment_resetoassword也是这样的

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.Resetpassword">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
    android:id="@+id/sv_fg_reset_"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg"
        android:layout_marginStart="50dp"
        android:layout_marginEnd="50dp"
        android:layout_marginTop="40dp">

        <RelativeLayout
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:id="@+id/rl_fg_reset_backarrowLayout">
            <ImageView
                android:id="@+id/iv_fg_reset_back"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_centerInParent="true"
                android:src="@drawable/back_black"/>
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/rl_fg_resrt_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:background="@drawable/circular_logo"
            android:backgroundTint="@color/colorOrange2"/>
        <com.kookyapps.astrotelluserapp.CustomViews.PoppinsBoldTextView
            android:id="@+id/tv_fg_reset_resetText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_below="@+id/rl_fg_resrt_logo"
            android:textSize="21sp"
            android:text="@string/resetPasswordTitle"
            android:textColor="@color/colorBlack2"/>
        <com.kookyapps.astrotelluserapp.CustomViews.PopinsRegularTextView
            android:id="@+id/tv_fg_reset_enterText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tv_fg_reset_resetText"
            android:textSize="12sp"
            android:text="@string/enterdetails"
            android:textColor="@color/grey2" />
        <RelativeLayout
            android:id="@+id/rl_fg_reset_newpassLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_below="@+id/tv_fg_reset_enterText">
            <ImageView
                android:id="@+id/iv_fg_reset_newpass"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:src="@drawable/lock_deselect"/>
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/et_fg_reset_newpass"
                android:layout_toRightOf="@+id/iv_fg_reset_newpass"
                android:layout_marginLeft="10dp"
                android:hint="@string/newpass"
                android:background="@android:color/transparent"/>
            <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:id="@+id/iv_fg_reset_eye"
                android:src="@drawable/eye_deselect"
                android:layout_marginRight="20dp"
                android:layout_alignParentRight="true"/>
        </RelativeLayout>
        <view
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:id="@+id/v_fg_reset_newpass"
            android:layout_below="@+id/rl_fg_reset_newpassLayout"/>




        <RelativeLayout
            android:id="@+id/rl_fg_reset_confirmpassLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/rl_fg_reset_newpassLayout">
            <ImageView
                android:id="@+id/iv_fg_reset_confirmpass"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:src="@drawable/lock_deselect"/>
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/et_fg_reset_confirmpass"
                android:layout_toRightOf="@+id/iv_fg_reset_confirmpass"
                android:layout_marginLeft="10dp"
                android:hint="@string/confirmpass"
                android:background="@android:color/transparent"/>
            <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:id="@+id/iv_fg_reset_eye_confirmpass"
                android:src="@drawable/eye_deselect"
                android:layout_marginRight="20dp"
                android:layout_alignParentRight="true"/>
        </RelativeLayout>
        <view
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:id="@+id/v_fg_reset_confirmpass"
            android:layout_below="@+id/rl_fg_reset_confirmpassLayout"/>
        <RelativeLayout
                android:id="@+id/rl_fg_reset_resetbtn"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="20dp"
            android:background="@drawable/button_bg"
            android:layout_below="@+id/rl_fg_reset_confirmpassLayout">
            <com.kookyapps.astrotelluserapp.CustomViews.PopinsRegularTextView
                android:id="@+id/tv_fg_reset_resetPassText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/reset"
                android:layout_centerInParent="true"
                android:textColor="@color/colorWhite"
                android:textStyle="bold"/>
        </RelativeLayout>



    </RelativeLayout>
</ScrollView>

我需要在我的片段类中导入数据绑定,但我不知道该怎么做,我已经搜索了 https://developer.android.com/topic/libraries/data-binding 和 https://github.com/curioustechizen/android-ago/issues/28 还有一个我搜索并找到了 How to use data-binding with Fragment 但是就我而言,如果我写这个类它找不到这个库。 所以我尝试了这些,但我没有找到任何解决方案来解决我的问题,如果有人能真正帮助我,我会很感激他。

【问题讨论】:

  • 您是手动转换此 XML 布局还是使用内置转换器? Converter 添加 &lt;layout&gt; 标记并为您构建类,您可能还需要清理和重建您的项目,然后才能访问它。
  • 转换器添加了 标签 ???就我而言,我已经多次清理并重建了该标签。如果您知道我哪里错了,请告诉我详细信息吗?

标签: android data-binding


【解决方案1】:

您使用了错误的 view 标签,即 view 使用 View 而不是 view ,您的问题将得到解决。

【讨论】:

  • 我承认它应该是 View ,我正在纠正它,让我们看看会发生什么
  • 希望它能起作用,因为我在您的绑定代码中没有发现任何问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-28
  • 1970-01-01
  • 2017-07-20
  • 2019-02-23
  • 2015-11-21
  • 2019-01-24
  • 2016-04-10
相关资源
最近更新 更多