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);}
相关文章:
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.and…...

华为云Flexus+DeepSeek征文 | Flexus X实例助力 Dify-LLM 一键部署:性能跃升与成本优化的革新实践
引言 在AI大模型应用快速普及的背景下,企业对低门槛部署、高性能算力与成本可控的需求日益迫切。华为云推出的Flexus X实例,作为专为AI工作负载优化的新一代算力底座,通过1.6倍算力提升、关键业务6倍加速、综合降本30%等核心优势,…...
曼昆经济学原理第九版目录
格里高利曼昆的《经济学原理》(Principles of Economics)通常分为34章(第9版,2024年英文版),分为微观经济学(第1-18章)和宏观经济学(第19-34章)两部分 第一部…...

数据库blog7_MySql的下载与配置准备
🌿MySql下载 🍂1.应用版本选择 选择社区版,免费适合初学者 相关链接下载页面下载界面介绍 🍂2.OS版本选择 根据自己的OS类型(Windows/Linux(CentOS/Ubuntu …)/macOS)选择对应版本…...

YOLOv11助力地铁机场安检!!!一键识别刀具
文末有完整代码出处 随着现代社会的高速发展,交通工具和公共场所的安全管理面临着前所未有的挑战。尤其在机场、地铁、车站等公共安全检查点,如何提高安检效率、精准识别危险物品,成为了亟待解决的问题。在传统的安检过程中,X光图…...

RFID工业读写器的场景化应用选型指南
RFID工业读写器是上海岳冉RFID专为工业场景设计的高性能射频识别设备,核心功能围绕高效数据采集与可靠传输展开。其基础能力包括多协议支持(如ISO 18000-6C)与多标签防碰撞处理,可同时读取/写入EPC编码、用户数据等标签信息&#…...
java中的线程安全的集合
1.ConcurrentHashMap。 key,value结构。 jdk1.7通过分段锁保证不同段同时操作是线程安全的,但并发不足,jdk1.8通过node节点锁和CAS保证并发安全。不同node节点可以并发读写。通过它的computer,computerIfAbsent,等可以保证原子更新value。ifAbsent表示有…...

单片机如何快速实现查看实时数据
在用 Keil 做调试的时候,最让人头秃的是什么? 不是写代码的BUG,而是:这个条件变量是什么情况?为什么没进入这个判断?我代码跑到哪里了? 其实本质上都是通过变量判断代码的执行顺序有没有问题 …...

go实现钉钉三方登录
钉钉的的官方开发文档中只给出了java实现三方登录的,我们准备用go语言来实现 实现网页方式登录应用(登录第三方网站) - 钉钉开放平台 首先就是按照文档进行操作,备注好网站的信息 获得应用凭证,我们后面会用到 之后…...
YOLOv1 详解:单阶段目标检测算法的里程碑
在目标检测领域,YOLO(You Only Look Once)系列算法凭借其高效性和实用性,成为了行业内的明星算法。其中,YOLOv1 作为 YOLO 系列的开山之作,首次提出了单阶段目标检测的思想,彻底改变了目标检测算…...
5G 核心网切换机制全解析:XN、N2 与移动性注册对比
摘要 本文深入探讨了 5G 核心网中的三种关键切换方式:基于 XN 接口的切换、基于 N2 接口的切换以及移动性注册更新机制。通过对比分析它们的原理、应用场景和技术差异,帮助读者全面理解 5G 网络中用户移动性管理的核心技术。 1. 引言 随着 5G 技术的广泛应用,用户对网络连…...

物流配送优化实战:用遗传算法破解选址难题
在电商与供应链高速发展的今天,物流配送成本优化始终是企业竞争力的核心议题之一。想象一下,当你面对 20 个分布在不同坐标的客户点、7 个可选配送中心和 1 个发件网点时,如何用最省钱的方式完成配送?今天我们就来拆解一个真实的物…...

Linux 个人用户设置账号密码环境变量,四种方式
一、需要明白以下2点: 1、Linux 的环境变量是保存在变量 PATH 中,可通过 Linux shell 命令 echo $PATH 查看输出内容,或者直接输入 export 查看,或者输入 env 查看 2、Linux环境变量值之间是通过冒号进行隔开的( : ) 格式为&am…...

Three.js搭建小米SU7三维汽车实战(5)su7登场
汽车模型加载 我们在sktechfab上下载的汽车是glb的文件格式,所以使用gltfLoader进行加载。这里将小车直接加载进来看看效果; import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js"; ....其余代码省略 const gltfLoader new GLT…...
关于 SSE(Server-Sent Events)过程的简要解剖
Js前端:发送普通请求 fetch(...) .then(()>{}) .catch(()>{})Java后端:接收请求后调用请求处理函数,函数返回一个emiiter对象 public SseEmitter handleRequest(...) {// 创建一个 SseEmitter 对象,用于发送 SSE 事件SseE…...

格恩朗管段超声波流量计:流量测量先锋
在流量测量技术不断迭代的浪潮中,格恩朗自 2019 年创立起,便以开拓者的姿态投身其中,致力于为全球用户提供先进、精准的流量测量解决方案。其旗下的管段超声波流量计,一经推出,便迅速吸引了行业的目光,成为…...
重构开发范式!飞算JavaAI革新Spring Cloud分布式系统开发
分布式系统凭借高可用性、可扩展性等核心优势,成为大型软件项目的标配架构。Spring Cloud作为Java生态最主流的分布式开发框架,虽被广泛应用于微服务架构搭建,但其传统开发模式却面临效率瓶颈——从服务注册中心配置到网关路由规则编写&#…...

图论 判断是否有环
前言:有点忘记是怎么判断一个图中是否是有环 如果是一个无向图,其实可以直接dfs,加上一个vis数组来一起判断 如果是有向图呢, class Solution:def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool…...
(请关注)Oracle性能调优、优化总结调优参考直接应用,性能提升实用案例
Oracle性能调优涉及SQL优化、索引设计、参数配置、存储优化等多个方面。以下是一些常见的性能调优方法及示例,涵盖核心场景和最佳实践。 1. SQL优化 示例1:使用绑定变量减少硬解析 ```sql -- 错误示例(硬解析频繁) SELECT * FROM employees WHERE employee_id = 100; …...

EasyDarwin的配置与使用
一.语言配置 准备go语言 All releases - The Go Programming Language 增加系统环境变量 让其生效 二.项目配置 Clone项目并解压 git clone https://github.com/EasyDarwin/EasyDarwin.git cd EasyDarwin go mod tidy 紧接着 make build/linux cd build cd EasyDarwin-lin-&qu…...
PostgreSQL日志管理完整方案(AI)
一、日志系统配置 1.1 核心参数配置 在postgresql.conf中进行以下设置: 启用日志收集:logging_collector on日志存储路径:log_directory ‘/var/log/postgresql’日志命名规则:log_filename ‘postgresql-%a.log’ÿ…...

【Android】基于SurfaceControlViewHost实现跨进程渲染
1 前言 本文将介绍基于 SurfaceControlViewHost 实现跨进程渲染普通 View 和 GlSurfaceView,力求用最简单的 Demo,介绍 SurfaceControlViewHost 的应用,方便读者轻松扣出核心代码应用到自己的业务中。 核心代码片段如下。 1)服务端…...

vue+ThreeJs 创造自动选择的甜甜圈(圆环)
嗨,我是小路。今天主要和大家分享的主题是“vueThreeJs 创造自动选择的甜甜圈”。 一个漂浮在页面中央的 3D 圆环,多个图标/文本/图片均匀分布在圆周上。它会自动缓慢旋转,形成动态视觉焦点。这就是今天要搭建的项目,并对…...

能说一下JVM的内存区域吗
根据Java虚拟机的规范,JVM的内存区域可以细分为程序计数器、虚拟机栈、本地方法栈、堆和方法区。 其中方法区和线程是共享的,虚拟机栈、本地方法区和程序计数器是线程私有的。 介绍一下程序计数器? 程序计数器也被称为PC寄存器。是一块较小…...

东方仙盟_灵颜妙手——表单样式——仙盟创梦IDE
代码 .东方仙盟_灵颜妙手 {background-color: #f0f8ff;padding: 10px;display: block;width:100%;height: 100%;}.东方仙盟_灵颜妙手 .表单 {max-width: 800px;margin: 0 auto;background-color: white;border-radius: 8px;box-shadow: 0 0 10px rgba(0, 123, 255, 0.1);paddin…...

输入一串字符,统计其中字母的个数
#include <stdio.h> int main() { char ch; int count 0; printf("请输入一串字符:\n"); while ((ch getchar())! \n) { if ((ch > a && ch < z) || (ch > A && ch < Z)) { count; } } printf("字母的个数为&a…...

进程IO之 进程
一、进程相关概念 1.什么是进程 程序:静态的,编译好的可执行文件,存放在磁盘中的指令和数据的集合 进程:动态的,是程序的一次执行过程,是独立的可调度的任务 2.进程的特点 (1)对…...

OpenGL Chan视频学习-5 Vertex Attributes and Layouts in OpenGL
bilibili视频链接: 【最好的OpenGL教程之一】https://www.bilibili.com/video/BV1MJ411u7Bc?p5&vd_source44b77bde056381262ee55e448b9b1973 一、知识点整理 1.1.OpenGL管线工作流程 为显卡提供绘制的所有数据,并将数据存储在GPU内存使用着色器&…...

ESP32学习笔记_Peripherals(3)——ADC
摘要 本博客介绍了ESP32-S3芯片内置SAR ADC的原理、参考电压、分辨率、信号衰减等基础知识,并讲解了如何使用ESP-IDF驱动库实现ADC的连续采样(DMA)功能,演示了多通道模拟信号(如摇杆模块)的采集与处理流程…...

QT学习一
对于选择qmake还是cmake,现在写的暂时先用qmake 1.命名规范和快捷键 2.按钮控件常用API //创建第一个按钮QPushButton * btn new QPushButton;//让btn对象 依赖在mywidget窗口中btn->setParent(this);//显示文本btn->setText("第一个按钮");//创建…...