在recyclerview android

时间:2019-04-11 18:30:35

标签: android android-databinding custom-view recyclerview-layout

嗨,我正在使用其中带有customview的RecyclerView数据绑定。

在添加CustomView之前,其工作正常。添加后得到BindingImpl错误,例如 错误:找不到符号导入appPackage.databinding.CheckoutBookCardBindingImpl; ^符号:类CheckoutBookCardBindingImpl位置:包appPackage.databinding

布局文件在下面

<data>

    <variable
        name="bookWithDownloadInfo"
        type="appPackage.feature.bookbag.model.BookWithDownloadInfo" />
</data>

<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/dimen_10dp"
    android:background="@color/white">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/checkout_parent_top_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/dimen_10dp">

            <ImageView
                android:id="@+id/img_checkout_book_banner"
                android:layout_width="108dp"
                android:layout_height="@dimen/dimen_150dp"
                android:layout_alignParentStart="true"
                android:layout_marginStart="@dimen/dimen_10dp"
                android:layout_marginEnd="@dimen/dimen_10dp"
                android:contentDescription="@string/desc_checkout_book_banner"
                app:banner_image_src="@{bookWithDownloadInfo.book}" />

            <LinearLayout
                android:id="@+id/book_name_container"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dimen_90dp"
                android:layout_toEndOf="@id/img_checkout_book_banner"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txt_checkout_book_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/dimen_5dp"
                    android:fontFamily="@font/roboto_medium"
                    android:maxLines="2"
                    android:textColor="@color/color_005493"
                    android:textSize="@dimen/dimen_18sp"
                    app:book_title="@{bookWithDownloadInfo.book}"
                    tools:text="@string/book_title" />

                <TextView
                    android:id="@+id/txt_checkout_book_author_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/dimen_5dp"
                    android:fontFamily="@font/roboto_italic"
                    android:text="@string/author_name_or_kind"
                    android:textSize="@dimen/dimen_14sp"
                    app:book_author="@{bookWithDownloadInfo.book}"
                    tools:text="Author Name or Kind" />
            </LinearLayout>

            <ImageView
                android:id="@+id/img_checkout_book_media_type"
                android:layout_width="@dimen/dimen_30dp"
                android:layout_height="@dimen/dimen_30dp"
                android:layout_below="@id/book_name_container"
                android:layout_marginStart="@dimen/dimen_5dp"
                android:layout_toEndOf="@id/img_checkout_book_banner"
                android:contentDescription="@string/desc_media_type"
                android:padding="@dimen/dimen_5dp"
                android:src="@drawable/icon_audiobook"
                app:book_media_type="@{bookWithDownloadInfo.book}" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/book_name_container"
                android:layout_gravity="center"
                android:layout_toEndOf="@id/img_checkout_book_media_type"
                android:gravity="center"
                android:padding="@dimen/dimen_5dp"
                android:textColor="@color/black"
                android:textSize="@dimen/dimen_14sp"
                app:media_type="@{bookWithDownloadInfo.book}"
                tools:text="Media type" />

            <TextView
                android:id="@+id/txt_checkout_book_due"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/img_checkout_book_media_type"
                android:layout_marginStart="@dimen/dimen_5dp"
                android:layout_marginTop="@dimen/dimen_10dp"
                android:layout_toEndOf="@id/img_checkout_book_banner"
                android:text="@string/checkout_book_due"
                android:textColor="@color/black"
                android:textSize="@dimen/dimen_14sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/txt_checkout_book_due_value"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/img_checkout_book_media_type"
                android:layout_marginTop="@dimen/dimen_10dp"
                android:layout_toEndOf="@id/txt_checkout_book_due"
                android:text="@string/june_2_2018"
                android:textColor="@color/black"
                android:textSize="@dimen/dimen_14sp"
                tools:text="June 2, 2018" />

            <Button
                android:id="@+id/btn_checkout_book_download"
                android:layout_width="@dimen/dimen_130dp"
                android:layout_height="@dimen/dimen_40dp"
                android:layout_below="@id/txt_checkout_book_due"
                android:layout_marginStart="@dimen/dimen_5dp"
                android:layout_marginTop="@dimen/dimen_10dp"
                android:layout_marginEnd="@dimen/dimen_10dp"
                android:background="@drawable/action_button_background"
                android:fontFamily="@font/roboto_medium"
                android:text="@string/action_download"
                android:textAllCaps="false"
                android:textColor="@color/white"
                android:textSize="@dimen/dimen_15sp" />

            <!--for downloaded book action-->
            <Button
                android:id="@+id/btn_checkout_book_open"
                android:layout_width="@dimen/dimen_130dp"
                android:layout_height="@dimen/dimen_40dp"
                android:layout_below="@id/txt_checkout_book_due"
                android:layout_marginStart="@dimen/dimen_5dp"
                android:layout_marginTop="@dimen/dimen_10dp"
                android:layout_marginEnd="@dimen/dimen_10dp"
                android:background="@drawable/action_button_background"
                android:fontFamily="@font/roboto_medium"
                android:text="@string/action_open"
                android:textAllCaps="false"
                android:textColor="@color/white"
                android:textSize="@dimen/dimen_15sp" />

            <Button
                android:id="@+id/btn_checkout_book_return"
                android:layout_width="@dimen/dimen_130dp"
                android:layout_height="@dimen/dimen_40dp"
                android:layout_below="@id/txt_checkout_book_due"
                android:layout_marginTop="@dimen/dimen_10dp"
                android:layout_toEndOf="@id/btn_checkout_book_download"
                android:background="@drawable/action_button_background"
                android:fontFamily="@font/roboto_medium"
                android:text="@string/action_return"
                android:textAllCaps="false"
                android:textColor="@color/white"
                android:textSize="@dimen/dimen_15sp" />

            <!--for downloaded book action-->
            <Button
                android:id="@+id/btn_checkout_book_remove"
                android:layout_width="@dimen/dimen_130dp"
                android:layout_height="@dimen/dimen_40dp"
                android:layout_below="@id/txt_checkout_book_due"
                android:layout_marginTop="@dimen/dimen_10dp"
                android:layout_toEndOf="@id/btn_checkout_book_open"
                android:background="@drawable/action_button_background"
                android:fontFamily="@font/roboto_medium"
                android:text="@string/action_remove"
                android:textAllCaps="false"
                android:textColor="@color/white"
                android:textSize="@dimen/dimen_15sp" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/downloadProgressbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/color_005493_trans">

            <appPackage.feature.common.view.CircularProgressView
                android:id="@+id/downloadProgressbar"
                android:layout_width="@dimen/dimen_220dp"
                android:layout_height="@dimen/dimen_220dp"
                android:layout_centerInParent="true"
                android:backgroundTintMode="add"
                app:adpgb_background_color="@android:color/transparent"
                app:adpgb_circle_starting_degree="-89"
                app:adpgb_finished_color="@android:color/transparent"
                app:adpgb_finished_stroke_width="@dimen/dimens_10dp"
                app:adpgb_progress="@{bookWithDownloadInfo.downloadPercent}"
                app:adpgb_show_text="false"
                app:adpgb_unfinished_color="@color/white_trans"
                app:adpgb_unfinished_stroke_width="@dimen/dimen_74dp" />

            <ImageView
                android:id="@+id/downloadOptions"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_marginEnd="@dimen/dimen_30dp"
                android:layout_marginBottom="@dimen/dimens_20dp"
                android:src="@drawable/ic_progress_3_dots" />

            <ImageView
                android:id="@+id/cancelDownload"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/downloadOptions"
                android:layout_alignParentEnd="true"
                android:layout_marginEnd="@dimen/dimens_20dp"
                android:layout_marginBottom="@dimen/dimen_30dp"
                android:src="@drawable/cancel_download" />

        </RelativeLayout>

        <!--<include
            android:id="@+id/downloadProgressbarLayout"
            layout="@layout/download_circular_progress_bar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"
            bind:bookDownloadInfo="@{bookWithDownloadInfo}" />-->
    </FrameLayout>
</androidx.cardview.widget.CardView>

自定义视图为appPackage.feature.common.view.CircularProgressView

它是一个Java类,可扩展View(用于显示针对应用程序要求定制的进度)

它具有如下的setter方法

该类中的一些代码段。我正在使用Kotlin作为开发语言。

公共类CircularProgressView扩展了视图{

private Paint finishedPaint;
private Paint unfinishedPaint;
private Paint innerCirclePaint;

public CircularProgressView(Context context) {
    this(context, null);
}

public CircularProgressView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}

public void setAdProgress(int percent) {
    if (percent >= 0) {
        setProgress(percent);
    }
}

}

在自定义视图上进行数据绑定时,如何解决该错误。准备在需要时提供搬家信息。

1 个答案:

答案 0 :(得分:0)

您的二传手应该看起来像这样:

public void setAdpgb_progress(int adpgb_progress) {
    this.adpgb_progress = adpgb_progress;
}

还要确保检查是否正确记录了更多的数据绑定错误信息。 enter image description here