android實現使用RecyclerView詳細

顯示頁面代碼:activity_category_inventory.xml代碼:

<?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"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="30dp"android:orientation="horizontal"><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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><LinearLayoutandroid:layout_width="match_parent"android:layout_height="440dp"android:layout_marginTop="5dp"android:orientation="horizontal"><ScrollViewandroid:layout_width="fill_parent"android:layout_height="440dp"><HorizontalScrollViewandroid:layout_width="match_parent"android:layout_height="440dp"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="440dp"android:orientation="horizontal"><!--  此處省略的組件的配置  --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" />--><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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.RecyclerViewandroid:id="@+id/RecyclerView"android:layout_width="match_parent"android:layout_height="match_parent"android:visibility="visible" /><ListViewandroid: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><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginBottom="3dp"><CheckBoxandroid:id="@+id/All_checkbox"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="全選"android:focusable="false"android:focusableInTouchMode="false" /><TextViewandroid: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" /><Buttonandroid: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" /><Buttonandroid: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" /><Buttonandroid: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" /><Buttonandroid: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代碼:

<?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"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="100dp"android:layout_marginBottom="10dp"android:background="@color/gray1"android:orientation="horizontal"><LinearLayoutandroid:layout_width="390dp"android:layout_height="100dp"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:orientation="horizontal"><CheckBoxandroid:id="@+id/pro_checkbox"android:layout_width="wrap_content"android:layout_height="wrap_content"android:focusable="false"android:focusableInTouchMode="false" /><TextViewandroid: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" /><TextViewandroid:id="@+id/TextView_TaskName"android:layout_width="200dp"android:layout_height="60dp"android:gravity="center"android:text="@string/stockitem"android:textColor="@color/colorblack" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="40dp"android:orientation="horizontal"><TextViewandroid: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" /><TextViewandroid: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" />--><!-- 減號按鈕 --><TextViewandroid: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" /><EditTextandroid: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" /><!-- 加號按鈕 --><TextViewandroid: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><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid:id="@+id/tvCount"android:layout_width="50dp"android:layout_height="100dp"android:background="@drawable/textview_right_border_simple"android:textAlignment="center"android:textSize="12sp" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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" /><TextViewandroid: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代碼:

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@Overridepublic ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from(context).inflate(R.layout.item_recycler_view, parent, false);return new ViewHolder(view);}@Overridepublic 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() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic 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() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic 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); // 標記監聽器以便后續移除}@Overridepublic int getItemCount() {return cartItems.size();}// 定義回調接口(可選)public interface OnQuantityChangeListener {void onQuantityChanged(PojoCard item);}
}

CategoryInventoryActivity代碼:

 private RecyclerView recyclerView;private ShoppingInCartAdapter shoppinginCartAdapter;private List<PojoCard> mArrCard;@Overrideprotected void onCreate(Bundle savedInstanceState) {// 綁定 RecyclerViewrecyclerView = findViewById(R.id.RecyclerView);recyclerView.setLayoutManager(new LinearLayoutManager(this)); // 必須設置布局管理器shoppinginCartAdapter = new ShoppingInCartAdapter(mArrCard, this);recyclerView.setAdapter(shoppinginCartAdapter);}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/83179.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/83179.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/83179.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【SpringBoot實戰】優雅關閉服務

文章目錄 一、什么是優雅關閉&#xff1f;二、優雅關閉的核心步驟三、SpringBoot優雅關閉實現四、關鍵注意事項1. 超時時間必須配置2. 信號支持局限性3. 特殊請求處理 五、底層實現原理六、總結 一、什么是優雅關閉&#xff1f; 優雅關閉&#xff08;Graceful Shutdown&#x…

C++哈希表:unordered系列容器詳解

本節目標 1.unordered系列關聯式容器 2.底層結構 3.模擬實現 4.哈希的應用 5.海量數據處理面試題 unordered系列關聯式容器 在c98中&#xff0c;STL提供了底層為紅黑樹結構的一系列關聯式容器&#xff0c;在查詢時效率可以達到logN&#xff0c;即最差的情況下需要比較紅…

java操作服務器文件(把解析過的文件遷移到歷史文件夾地下)

第一步導出依賴 <dependency><groupId>org.apache.sshd</groupId><artifactId>sshd-core</artifactId><version>2.13.0</version></dependency> 第二步寫代碼 public void moveFile( List<HmAnalysisFiles> hmAnalys…

Oracle OCP認證的技術定位怎么樣?

一、引言&#xff1a;Oracle OCP認證的技術定位? Oracle Certified Professional&#xff08;OCP&#xff09;認證是數據庫領域含金量最高的國際認證之一&#xff0c;其核心價值在于培養具備企業級數據庫全生命周期管理能力的專業人才。隨著數字化轉型加速&#xff0c;OCP認證…

TK海外搶單源碼/指定卡單

? 搶單源碼&#xff0c;有指定派單&#xff0c;打針&#xff0c;這套二改過充值跳轉客服 前端vue 后端php 兩端分離 可二開 可以指定卡第幾單&#xff0c;金額多少&#xff0c; 前后端開源 PHP7.2 MySQL5.6 前端要www.域名&#xff0c;后端要admin.域名 前端直接靜態 偽靜…

遠程線程注入

注入簡單來說就是讓別人的程序執行 你想要讓他執行的dll #include<iostream> #include<Windows.h> using namespace std;char szBuffer[] "C:\\Users\\20622\\source\\repos\\Dll1\\Debug\\test.dll"; //dll路徑void RemoteThreadInject(DWORD Pid,PCH…

【Java實戰】集合排序方法與長度獲取方法辨析(易懂版)

一、排序方法 1. 對List排序的兩種方式 方式一Collections.sort() List<Integer> numbers Arrays.asList(3,1,4,2); Collections.sort(numbers); // 直接修改原list → [1,2,3,4]方式二&#xff1a;list.sort()&#xff08;Java8推薦&#xff09; List<String>…

企業級安全實踐:SSL/TLS 加密與權限管理(一)

引言 ** 在數字化轉型的浪潮中&#xff0c;企業對網絡的依賴程度與日俱增&#xff0c;從日常辦公到核心業務的開展&#xff0c;都離不開網絡的支持。與此同時&#xff0c;網絡安全問題也日益嚴峻&#xff0c;成為企業發展過程中不可忽視的重要挑戰。 一旦企業遭遇網絡安全事…

Java 大視界 -- Java 大數據在智能醫療影像數據壓縮與傳輸優化中的技術應用(227)

&#x1f496;親愛的朋友們&#xff0c;熱烈歡迎來到 青云交的博客&#xff01;能與諸位在此相逢&#xff0c;我倍感榮幸。在這飛速更迭的時代&#xff0c;我們都渴望一方心靈凈土&#xff0c;而 我的博客 正是這樣溫暖的所在。這里為你呈上趣味與實用兼具的知識&#xff0c;也…

Python編程基礎(一) | 變量和簡單數據類型

引言&#xff1a;很久沒有寫 Python 了&#xff0c;有一點生疏。這是學習《Python 編程&#xff1a;從入門到實踐&#xff08;第3版&#xff09;》的課后練習記錄&#xff0c;主要目的是快速回顧基礎知識。 練習1&#xff1a; 簡單消息 將一條消息賦給變量&#xff0c;并將其…

鴻蒙 HarmonyOS - SideBarContainer 組件自學指南

在日常開發中&#xff0c;如果你有類似「左側導航 右側內容」的布局需求&#xff0c;比如后臺管理界面、文件管理器、設置頁等&#xff0c;??SideBarContainer?? 是非常值得掌握的組件。它自帶側邊欄和主內容區的分離機制&#xff0c;還支持折疊、拖拽、控制按鈕和多種顯示…

CppCon 2014 學習:Practical Functional Programming

這段內容是對**在 C 中使用函數式編程&#xff08;Functional Programming, FP&#xff09;**可以做什么的簡要介紹&#xff0c;下面是逐條的翻譯與理解&#xff1a; Introduction 簡介 在 C 中使用函數式編程&#xff08;FP&#xff09;可以做什么&#xff1f; 1. 編寫強大…

飛牛NAS+Docker技術搭建個人博客站:公網遠程部署實戰指南

文章目錄 前言1. Docker下載源設置2. Docker下載WordPress3. Docker部署Mysql數據庫4. WordPress 參數設置5. 飛牛云安裝Cpolar工具6. 固定Cpolar公網地址7. 修改WordPress配置文件8. 公網域名訪問WordPress總結 前言 在數字化浪潮中&#xff0c;傳統網站搭建方式正面臨前所未…

ComfyUI+阿里Wan2.1+內網穿透技術:本地AI視頻生成系統搭建實戰

文章目錄 前言1.軟件準備1.1 ComfyUI1.2 文本編碼器1.3 VAE1.4 視頻生成模型 2.整合配置3. 本地運行測試4. 公網使用Wan2.1模型生成視頻4.1 創建遠程連接公網地址 5. 固定遠程訪問公網地址總結 前言 各位技術愛好者&#xff0c;今天為您帶來一組創新性的AI應用方案&#xff01…

n8n:技術團隊的智能工作流自動化助手

在當前數字化時代,自動化已經成為提高效率和減輕人工工作負擔的一大推動力。今天,我們要為大家介紹一款極具潛力的開源項目——n8n,它不僅擁有廣泛的應用場景,還具備內置AI功能,能夠完全滿足技術團隊的高效工作需求。n8n的出現,為技術團隊提供了自由編程與快速自動化構建…

1,QT的編譯教程

目錄 整體流程: 1,新建project文件 2,編寫源代碼 3,打開QT的命令行窗口 4,生成工程文件(QT_demo.pro) 5,生成Make file 6,編譯工程 7,運行編譯好的可執行文件 整體流程: 1,新建project文件 新建文本文件,后綴改為.cpp 2,編寫源代碼

深度學習論文: FastVLM: Efficient Vision Encoding for Vision Language Models

深度學習論文: FastVLM: Efficient Vision Encoding for Vision Language Models FastVLM: Efficient Vision Encoding for Vision Language Models PDF: https://www.arxiv.org/abs/2412.13303 PyTorch代碼: https://github.com/shanglianlm0525/CvPytorch PyTorch代碼: https…

十一、【核心功能篇】測試用例管理:設計用例新增編輯界面

【核心功能篇】測試用例管理&#xff1a;設計用例新增&編輯界面 前言準備工作第一步&#xff1a;創建測試用例相關的 API 服務 (src/api/testcase.ts)第二步&#xff1a;創建測試用例編輯頁面組件 (src/views/testcase/TestCaseEditView.vue)第三步&#xff1a;配置測試用例…

三、web安全-信息收集

1、信息搜集的重要性 &#xff08;1&#xff09;明確攻擊面 信息搜集能讓滲透測試人員清晰地勾勒出目標系統的邊界&#xff0c;包括其網絡拓撲結構、開放的服務端口、運行的軟件系統等。例如&#xff0c;通過信息搜集發現目標企業除了對外提供官網服務外&#xff0c;還有一個…

生活小記啊

最近生活上的事情還是蠻多的&#xff0c;想到哪寫到哪。 工作 三月的某個周六&#xff0c;正在加班寫技術方案&#xff0c;大晚上寫完了聽到調動通知&#xff0c;要去新的團隊了。 還是蠻不舍的&#xff0c;看著產品從無到有&#xff0c;一路走過來&#xff0c;傾注了不少感…