android实现使用RecyclerView详细

显示页面代码:activity_category_inventory.xml代码:

bash 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CategoryInventoryActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="30dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/TextviewBorrow_userNames1"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/category_inventory_in_user_name"
            android:textAlignment="viewEnd"
            android:textColor="@color/black"
            android:textSize="14sp" />

        <TextView

            android:id="@+id/TextviewIn_userNames"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/category_inventory_in_user_name"
            android:textColor="@color/black"
            android:textSize="14sp" />

        <TextView

            android:id="@+id/TextView_category_inventory_in_time"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/category_inventory_in_time"
            android:textAlignment="viewEnd"
            android:textColor="@color/black"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/textViewnowcategory_inventory_in_time"
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/category_inventory_in_time"
            android:textColor="@color/black"
            android:textSize="14sp" />


    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="440dp"
        android:layout_marginTop="5dp"

        android:orientation="horizontal">

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="440dp">

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="440dp">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="440dp"
                    android:orientation="horizontal">
                    <!--  此处省略的组件的配置  -->

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal">

                            <TextView
                                android:id="@+id/TextView_id"
                                android:layout_width="50dp"
                                android:layout_height="wrap_content"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_id"
                                android:textAlignment="viewEnd"
                                android:textColor="#005500"
                                android:textSize="14sp"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/tvAssetname"
                                android:layout_width="200dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_assetname"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
                            <TextView
                                android:id="@+id/TextView_in_number"
                                android:layout_width="140dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_category_inventory_number"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
<!--                          <TextView-->
<!--                                android:id="@+id/TextView_do"-->
<!--                                android:layout_width="100dp"-->
<!--                                android:layout_height="wrap_content"-->
<!--                                android:layout_weight="1"-->
<!--                                android:textStyle="bold"-->
<!--                                android:background="@drawable/border_background"-->
<!--                                android:text="@string/txt_category_inventory_do"-->
<!--                                android:textAlignment="center"-->
<!--                                android:textColor="@android:color/black"-->
<!--                                android:textSize="14sp" />-->
                            <TextView
                                android:id="@+id/TextView_data"
                                android:layout_width="250dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_deviceNo"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/TextView_state"
                                android:layout_width="70dp"
                                android:layout_height="wrap_content"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_state"
                                android:textAlignment="center"
                                android:textColor="#550000"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvCategoryNo"
                                android:layout_width="200dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_categoryNo"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvCategoryName"
                                android:layout_width="200dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"

                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_categoryName"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/TextView_EPC"
                                android:layout_width="180dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_tid"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
                            <TextView
                                android:id="@+id/tvwarehouseNo"
                                android:layout_width="300dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_warehouseName"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
                            <TextView
                                android:id="@+id/tvwarehouseName"
                                android:layout_width="300dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_warehouseName"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
                            <TextView
                                android:id="@+id/tvLocationNo"
                                android:layout_width="200dp"
                                android:layout_height="wrap_content"


                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_locationName"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
                            <TextView
                                android:id="@+id/tvLocationName"
                                android:layout_width="200dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_locationName"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvSIM"
                                android:layout_width="100dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"

                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_SIM"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvSupplier_name"
                                android:layout_width="80dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_supplier_name"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvModel"
                                android:layout_width="90dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_model"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvFirmware_version"
                                android:layout_width="90dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_firmware_version"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvequimentName"
                                android:layout_width="120dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_equimentName"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvRemarks1"
                                android:layout_width="150dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_remarks1"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvRemarks2"
                                android:layout_width="150dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_remarks2"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvRemarks3"
                                android:layout_width="150dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_remarks3"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvRemarks4"
                                android:layout_width="150dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_remarks4"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvRemarks5"
                                android:layout_width="150dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:background="@drawable/border_background"
                                android:textStyle="bold"
                                android:text="@string/txt_remarks5"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvCount2"
                                android:layout_width="50dp"
                                android:layout_height="wrap_content"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/count"
                                android:textAlignment="center"

                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/TextView_RSSI"
                                android:layout_width="100dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_rssi"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvCreateup_date"
                                android:layout_width="90dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_createupDate"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />

                            <TextView
                                android:id="@+id/tvAssetNo"
                                android:layout_width="200dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_asset_no"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
                            <TextView
                                android:id="@+id/tvAssetIDs"
                                android:layout_width="210dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textStyle="bold"
                                android:background="@drawable/border_background"
                                android:text="@string/txt_category_inventory_asset_id"
                                android:textAlignment="center"
                                android:textColor="@android:color/black"
                                android:textSize="14sp" />
                        </LinearLayout>

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/RecyclerView"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:visibility="visible" />

                        <ListView
                            android:id="@+id/lvContent2"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:visibility="gone"
                            android:scrollbars="horizontal|vertical" />

                    </LinearLayout>


                </RelativeLayout>
            </HorizontalScrollView>

        </ScrollView>


    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp">
        <CheckBox
            android:id="@+id/All_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="全选"
            android:focusable="false"
            android:focusableInTouchMode="false" />
        <TextView
            android:id="@+id/tvCardCount2"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="1dp"
            android:gravity="center"
            android:text="0"
            android:textColor="#FF0000"
            android:textSize="24sp" />


        <Button
            android:id="@+id/btnScan2"
            android:layout_width="60dp"
            android:layout_height="40dp"
            android:layout_marginLeft="3dp"
            android:background="@drawable/button_style"
            android:text="@string/scan"
            android:textColor="@android:color/white"
            android:textSize="18sp" />

        <Button
            android:id="@+id/btnClear2"
            android:layout_width="60dp"
            android:layout_height="40dp"
            android:layout_marginLeft="3dp"
            android:background="@drawable/button_style"
            android:text="@string/clear"
            android:textColor="@android:color/white"
            android:textSize="18sp" />



        <Button
            android:id="@+id/btnSave2"
            android:layout_width="60dp"
            android:layout_height="40dp"
            android:layout_marginLeft="3dp"
            android:background="@drawable/button_style"
            android:text="@string/btn_category_inventory_in"
            android:textColor="@android:color/white"
            android:textSize="18sp" />

        <Button
            android:id="@+id/btnReturnInventory2"
            android:layout_width="60dp"
            android:layout_height="40dp"
            android:layout_marginLeft="3dp"
            android:background="@drawable/button_style"
            android:text="@string/btnQueryReturn"
            android:textColor="@android:color/white"
            android:textSize="18sp" />
    </LinearLayout>
</LinearLayout>

item_recycler_view.xml代码:

bash 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_marginBottom="10dp"
        android:background="@color/gray1"
        android:orientation="horizontal">


        <LinearLayout
            android:layout_width="390dp"
            android:layout_height="100dp"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal">

                <CheckBox
                    android:id="@+id/pro_checkbox"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:focusable="false"
                    android:focusableInTouchMode="false" />

                <TextView
                    android:id="@+id/TextView_TaskId"
                    android:layout_width="20dp"
                    android:layout_height="60dp"

                    android:gravity="center"
                    android:text="@string/txt_category_inventory_all_count"
                    android:textAlignment="viewStart"
                    android:textColor="@color/colorblack" />

                <TextView
                    android:id="@+id/TextView_TaskName"
                    android:layout_width="200dp"
                    android:layout_height="60dp"

                    android:gravity="center"
                    android:text="@string/stockitem"

                    android:textColor="@color/colorblack" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp"

                android:orientation="horizontal">

                <TextView
                    android:id="@+id/TextView_Count1"
                    android:layout_width="75dp"
                    android:layout_height="match_parent"

                    android:gravity="center"
                    android:text="@string/txt_category_inventory_all"
                    android:textAlignment="center"
                    android:textColor="@color/colorblack" />

                <TextView
                    android:id="@+id/TextView_AllCount"
                    android:layout_width="120dp"
                    android:layout_height="match_parent"

                    android:gravity="center"
                    android:text="@string/txt_category_inventory_all_count"
                    android:textAlignment="viewStart"
                    android:textColor="@color/colorblack" />

                <!--        <Button-->
                <!--            android:id="@+id/btn_minus"-->
                <!--            android:layout_width="60dp"-->
                <!--            android:layout_height="40dp"-->
                <!--            android:layout_marginLeft="5dp"-->
                <!--            android:layout_marginTop="5dp"-->
                <!--            android:layout_marginRight="10dp"-->
                <!--            android:layout_marginBottom="5dp"-->
                <!--            android:layout_weight="0.25"-->
                <!--            android:background="@drawable/button_style"-->
                <!--            android:gravity="center"-->
                <!--            android:text="@string/btndetail"-->
                <!--            android:textColor="@color/colorwhite"-->
                <!--            android:textSize="16sp" />-->

                <!-- 减号按钮 -->
                <TextView
                    android:id="@+id/btnMinus"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@drawable/circle_button2"

                    android:text="------"
                    android:textAlignment="center"
                    android:textColor="#FFFFFF"
                    android:textSize="26sp" />

                <EditText
                    android:id="@+id/EditText_In_number"
                    android:layout_width="65dp"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="2dp"
                    android:layout_marginRight="2dp"
                    android:layout_marginBottom="2dp"
                    android:background="@drawable/border_background"
                    android:inputType="number"
                    android:textAlignment="center" />
                <!-- 加号按钮 -->
                <TextView
                    android:id="@+id/btnPlus"
                    android:layout_width="40dp"
                    android:layout_height="40dp"

                    android:background="@drawable/circle_button"

                    android:text="+"
                    android:textAlignment="center"

                    android:textColor="#FFFFFF"
                    android:textSize="26sp" />
                <!--        <Button-->
                <!--            android:id="@+id/btn_add"-->
                <!--            android:layout_width="60dp"-->
                <!--            android:layout_height="40dp"-->
                <!--            android:layout_marginLeft="5dp"-->
                <!--            android:layout_marginTop="5dp"-->
                <!--            android:layout_marginRight="10dp"-->
                <!--            android:layout_marginBottom="5dp"-->
                <!--            android:layout_weight="0.25"-->
                <!--            android:background="@drawable/button_style"-->
                <!--            android:gravity="center"-->
                <!--            android:text="@string/btndetail"-->
                <!--            android:textColor="@color/colorwhite"-->
                <!--            android:textSize="16sp" />-->

            </LinearLayout>

        </LinearLayout>

        <TextView
            android:id="@+id/tvDeviceNo"
            android:layout_width="250dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tvState"
            android:layout_width="73dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_categoryNo"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_categoryName"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tvContent"
            android:layout_width="180dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_warehouseNo"
            android:layout_width="300dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_warehouseName"
            android:layout_width="300dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_locationNo"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_locationName"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_SIM"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_supplier_name"
            android:layout_width="85dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_model"
            android:layout_width="90dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_firmware_version"
            android:layout_width="90dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_equimentName"
            android:layout_width="120dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_remarks1"
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_remarks2"
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_remarks3"
            android:layout_width="155dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_remarks4"
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_remarks5"
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />


        <TextView
            android:id="@+id/tvCount"
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"

            android:textSize="12sp" />

        <TextView
            android:id="@+id/tvRssi"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@drawable/textview_right_border_simple"

            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_Createup_date"
            android:layout_width="90dp"
            android:layout_height="100dp"

            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_assetNo"
            android:layout_width="200dp"
            android:layout_height="100dp"

            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_assetId"
            android:layout_width="200dp"
            android:layout_height="100dp"

            android:layout_weight="1"
            android:background="@drawable/textview_right_border_simple"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="12sp" />
    </LinearLayout>
</LinearLayout>

java代码:

bash 复制代码
package com.uhf200.demo.ui.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.uhf200.demo.R;
import com.uhf200.demo.ui.model.PojoCard;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

// 假设使用 RecyclerView 和 ViewHolder 模式
public class ShoppingInCartAdapter extends RecyclerView.Adapter<ShoppingInCartAdapter.ViewHolder> {
    public List<PojoCard> cartItems; // 购物车数据列表
    private OnQuantityChangeListener listener; // 回调接口(可选)
    private Map<String, TextWatcher> watcherMap = new HashMap<String, TextWatcher>();
    private Context context;

    // ViewHolder 内部类
    public static class ViewHolder extends RecyclerView.ViewHolder {

        CheckBox checkBox;
        //  ImageView icon;
        EditText num;
       TextView name,price,type,reduce,add,
                id,tv_AssetName,tvDeviceNo,tvContent,tvCount,tv_AllCount,
                tvRssi,tv_SIM,tv_supplier_name, tv_model, tv_firmware_version,
                tv_remarks1,tv_remarks2,tv_remarks3,tv_remarks4,tv_remarks5,tv_equimentName,tv_assetNo,
                tv_categoryNo,tv_categoryName,tv_warehouseNo,
                tv_warehouseName,tv_locationNo,tv_locationName,tv_Createup_date,
                tvState,tv_assetId;
       // TextView tvName, tvQuantity;
       // Button btnAdd, btnSubtract;
        private LayoutInflater inflater;


        public ViewHolder(@NonNull View view) {
            super(view);
//            tvName = itemView.findViewById(R.id.item_name);
//            tvQuantity = itemView.findViewById(R.id.item_quantity);
//            btnAdd = itemView.findViewById(R.id.btn_add);
//            btnSubtract = itemView.findViewById(R.id.btn_subtract);

          //  view = inflater.inflate(R.layout.category_inventory_listitem,  parent,false);
            checkBox=(CheckBox) view.findViewById(R.id.pro_checkbox);

           id=(TextView) view.findViewById(R.id.TextView_TaskId);
            tv_AssetName=(TextView) view.findViewById(R.id.TextView_TaskName);
           num=(EditText) view.findViewById(R.id.EditText_In_number);


            tv_AllCount=(TextView) view.findViewById(R.id.TextView_AllCount);
           tvDeviceNo=(TextView) view.findViewById(R.id.tvDeviceNo);
            tvContent=(TextView) view.findViewById(R.id.tvContent);
            tvCount=(TextView) view.findViewById(R.id.tvCount);
            tvRssi=(TextView) view.findViewById(R.id.tvRssi);
            tv_SIM=(TextView) view.findViewById(R.id.tv_SIM);
           tv_supplier_name=(TextView) view.findViewById(R.id.tv_supplier_name);
           tv_model=(TextView) view.findViewById(R.id.tv_model);
           tv_firmware_version=(TextView) view.findViewById(R.id.tv_firmware_version);
           tv_remarks1=(TextView) view.findViewById(R.id.tv_remarks1);
           tv_remarks2=(TextView) view.findViewById(R.id.tv_remarks2);
           tv_remarks3=(TextView) view.findViewById(R.id.tv_remarks3);
            tv_remarks4=(TextView) view.findViewById(R.id.tv_remarks4);
           tv_remarks5=(TextView) view.findViewById(R.id.tv_remarks5);
            tv_equimentName=(TextView) view.findViewById(R.id.tv_equimentName);
           tv_assetNo=(TextView) view.findViewById(R.id.tv_assetNo);
            tv_categoryNo=(TextView) view.findViewById(R.id.tv_categoryNo);
            tv_categoryName=(TextView) view.findViewById(R.id.tv_categoryName);
           tv_warehouseNo=(TextView) view.findViewById(R.id.tv_warehouseNo);
           tv_warehouseName=(TextView) view.findViewById(R.id.tv_warehouseName);
            tv_locationNo=(TextView) view.findViewById(R.id.tv_locationNo);
           tv_locationName=(TextView) view.findViewById(R.id.tv_locationName);
            tvState=(TextView) view.findViewById(R.id.tvState);
            tv_assetId=(TextView) view.findViewById(R.id.tv_assetId);
            tv_Createup_date=(TextView) view.findViewById(R.id.tv_Createup_date);

            add=(TextView) view.findViewById(R.id.btnPlus);
           reduce=(TextView) view.findViewById(R.id.btnMinus);
        }

        public void bindData(PojoCard pojoCard) {
//            title.setText(item.getTitle());
//            price.setText(String.valueOf(item.getPrice()));

            id.setText(pojoCard.getId()+"");
            tv_AssetName.setText(pojoCard.getAsset_name().toString());
            num.setText(pojoCard.getOut_number()+"");
            tv_AllCount.setText(pojoCard.getAll_number()+"");
            tvDeviceNo.setText(pojoCard.getDevice_no().toString());
            tvContent.setText(pojoCard.getContent().toString());
            tvCount.setText(pojoCard.getCount()+"");
            tvRssi.setText(pojoCard.getRssi().toString());
            tv_SIM.setText(pojoCard.getSim().toString());
            tv_supplier_name.setText(pojoCard.getSupplier_name().toString());
            tv_model.setText(pojoCard.getModel().toString());
            tv_firmware_version.setText(pojoCard.getFirmware_version().toString());
            tv_remarks1.setText(pojoCard.getRemarks1().toString());
            tv_remarks2.setText(pojoCard.getRemarks2().toString());
            tv_remarks3.setText(pojoCard.getRemarks3().toString());
            tv_remarks4.setText(pojoCard.getRemarks4().toString());
            tv_remarks5.setText(pojoCard.getRemarks5().toString());
            tv_equimentName.setText(pojoCard.getEquiment_name().toString());
            tv_assetNo.setText(pojoCard.getAsset_no().toString());
            tv_categoryNo.setText(pojoCard.getCategory_no().toString());
            tv_categoryName.setText(pojoCard.getCategory_name().toString());
            tv_warehouseNo.setText(pojoCard.getWarehouse_no().toString());
            tv_warehouseName.setText(pojoCard.getWarehouse_name().toString());
            tv_locationNo.setText(pojoCard.getLocation_no().toString());
            tv_locationName.setText(pojoCard.getLocation_name().toString());
            tvState.setText(pojoCard.getState().toString());
            tv_assetId.setText(pojoCard.getId()+"");
            checkBox.setChecked(pojoCard.isCheckBox());
        }

    }


    // 更新整个数据源(可选)
    public void updateData(List<PojoCard> newItems) {
        cartItems = newItems;
        notifyDataSetChanged();
    }
    // 构造方法
    public ShoppingInCartAdapter(List<PojoCard> cartItems, OnQuantityChangeListener listener) {
        this.cartItems = cartItems;
        this.listener = listener;
    }

    public ShoppingInCartAdapter() {

    }
    // 构造函数
    public ShoppingInCartAdapter(List<PojoCard> items, Context context) {
        this.cartItems = items;
        this.context = context;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context)
                .inflate(R.layout.item_recycler_view, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

          PojoCard pojoCard = cartItems.get(position);
//        holder.tvName.setText(item.getName());
//        holder.tvQuantity.setText(String.valueOf(item.getQuantity()));
// 移除旧监听器
        if (watcherMap.containsKey(pojoCard.getId())) {
            holder.num.removeTextChangedListener(watcherMap.get(pojoCard.getId()));
        }
        holder.id.setText((position+1)+"");
        holder.tv_AssetName.setText(pojoCard.getAsset_name().toString());
        holder.num.setText(pojoCard.getIn_number()+"");
        holder.tv_AllCount.setText(pojoCard.getAll_number()+"");
        holder.tvDeviceNo.setText(pojoCard.getDevice_no().toString());
        holder.tvContent.setText(pojoCard.getContent().toString());
        holder.tvCount.setText(pojoCard.getCount()+"");
        holder.tvRssi.setText(pojoCard.getRssi().toString());
        holder.tv_SIM.setText(pojoCard.getSim().toString());
        holder.tv_supplier_name.setText(pojoCard.getSupplier_name().toString());
        holder.tv_model.setText(pojoCard.getModel().toString());
        holder.tv_firmware_version.setText(pojoCard.getFirmware_version().toString());
        holder.tv_remarks1.setText(pojoCard.getRemarks1().toString());
        holder.tv_remarks2.setText(pojoCard.getRemarks2().toString());
        holder.tv_remarks3.setText(pojoCard.getRemarks3().toString());
        holder.tv_remarks4.setText(pojoCard.getRemarks4().toString());
        holder.tv_remarks5.setText(pojoCard.getRemarks5().toString());
        holder.tv_equimentName.setText(pojoCard.getEquiment_name().toString());
        holder.tv_assetNo.setText(pojoCard.getAsset_no().toString());
        holder.tv_categoryNo.setText(pojoCard.getCategory_no().toString());
        holder.tv_categoryName.setText(pojoCard.getCategory_name().toString());
        holder.tv_warehouseNo.setText(pojoCard.getWarehouse_no().toString());
        holder.tv_warehouseName.setText(pojoCard.getWarehouse_name().toString());
        holder.tv_locationNo.setText(pojoCard.getLocation_no().toString());
        holder.tv_locationName.setText(pojoCard.getLocation_name().toString());
        holder.tvState.setText(pojoCard.getState().toString());
        holder.tv_assetId.setText(pojoCard.getId()+"");
        holder.checkBox.setChecked(pojoCard.isCheckBox());

//        holder.add=(TextView) view.findViewById(R.id.btnPlus);
//        holder.reduce=(TextView) view.findViewById(R.id.btnMinus);
        // 添加 TextWatcher(需处理复用问题)



     //   setupTextWatcher(holder.num, pojoCard, position);

        // 绑定"+"号点击事件
        holder.add.setOnClickListener(v -> {
            int currentPosition = holder.getAdapterPosition(); // 获取当前项位置
            if (currentPosition != RecyclerView.NO_POSITION) {
                PojoCard currentItem = cartItems.get(currentPosition);
                currentItem.setIn_number(currentItem.getIn_number() + 1); // 仅修改当前项
                notifyItemChanged(currentPosition); // 刷新当前项


                // 可选:通过回调通知外部更新总价等
                if (listener != null) {
                    listener.onQuantityChanged(currentItem);
                }
            }
        });

        // 类似处理"-"号按钮
        holder.reduce.setOnClickListener(v -> {
            int currentPosition = holder.getAdapterPosition();
            if (currentPosition != RecyclerView.NO_POSITION) {
                PojoCard currentItem = cartItems.get(currentPosition);
                if (currentItem.getIn_number() > 1) {
                    currentItem.setIn_number(currentItem.getIn_number() - 1);
                    notifyItemChanged(currentPosition);
                    if (listener != null) {
                        listener.onQuantityChanged(currentItem);
                    }

                }
            }
        });

// 创建并添加新监听器
        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void afterTextChanged(Editable s) {
                cartItems.get(holder.getAdapterPosition()).setContent(s.toString());
            }
        };

        holder.num.addTextChangedListener(watcher);

        watcherMap.put(pojoCard.getId()+"", watcher);
       // holder.bindData(pojoCard);

    }
    private void setupTextWatcher(EditText editText, final PojoCard item, final int position) {
        // 清除旧监听器,避免重复触发
        if (editText.getTag(R.id.EditText_In_number) != null) {
            editText.removeTextChangedListener((TextWatcher) editText.getTag(R.id.EditText_In_number));
        }

        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void afterTextChanged(Editable s) {
                try {
                    int quantity = Integer.parseInt(s.toString());
                    item.setOut_number(quantity); // 更新对应数据
                    // 可选:刷新单个 item 或通知数据变化
                    // notifyDataSetChanged();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        };

        editText.addTextChangedListener(watcher);
        editText.setTag(R.id.EditText_In_number, watcher); // 标记监听器以便后续移除
    }

    @Override
    public int getItemCount() {
        return cartItems.size();
    }

    // 定义回调接口(可选)
    public interface OnQuantityChangeListener {
        void onQuantityChanged(PojoCard item);
    }
}

CategoryInventoryActivity代码:

bash 复制代码
 private RecyclerView recyclerView;
 private ShoppingInCartAdapter shoppinginCartAdapter;
  private List<PojoCard> mArrCard;

 @Override
    protected void onCreate(Bundle savedInstanceState) {

   // 绑定 RecyclerView
        recyclerView = findViewById(R.id.RecyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this)); // 必须设置布局管理器
        shoppinginCartAdapter = new ShoppingInCartAdapter(mArrCard, this);
        recyclerView.setAdapter(shoppinginCartAdapter);
    }
相关推荐
liuyang-neu1 小时前
力扣 155.最小栈
java·算法·leetcode
Musennn2 小时前
leetcode98.验证二叉搜索树:递归法中序遍历的递增性验证之道
java·数据结构·算法·leetcode
WLKQ2 小时前
【力扣】关于链表索引
java·leetcode·链表
xujinwei_gingko4 小时前
Spring boot基础
java·spring boot
啊阿狸不会拉杆4 小时前
《软件工程》第 14 章 - 持续集成
java·ci/cd·软件工程
武昌库里写JAVA4 小时前
Vue3编译器:静态提升原理
java·开发语言·spring boot·学习·课程设计
bing_1585 小时前
HttpServletRequest 对象包含了哪些信息?
java·spring·mvc
xzdangelliu5 小时前
POI模板生成EXCEL 64000 style in a .xlsx Workbook
java·excel·poi
on the way 1235 小时前
Simple Factory(简单工厂)
java·简单工厂模式