如何从 editText 和 recyclerview 适配器的其他字段获取值以进行提交

How to get values from editText and other fields from recyclerview adapter for a submit

我想做的是创建一个提交过程,在该过程中,我会在提交之前检查每个项目,比较同一项目中的字段和 textview 中的条目。单击提交按钮时,我不太明白如何获取值。

这是 class 代码,我在其中初始化适配器并具有提交按钮:

public void buildDetailsAdapter(){
        //recycler view saleDetails
        SaleDetail saleDetail = new SaleDetail();
        final List<SaleDetail> saleDetailList = saleDetail.getSaleDetailsbyIdSaleHeader(idSaleHeader);
        Log.i(TAG, "buildProductsAdapter "+saleDetailList.size());
        MoneyDevolutionAdapter saleDetailAdapter = new MoneyDevolutionAdapter(saleDetailList, context);
        rcvMoneyDevolution.setAdapter(saleDetailAdapter);
    }

    public void initListeners(){
        btnDevolution.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG, "onClick: btnDevolution");

            }
        });
    } 

这是适配器代码:

public void onBindViewHolder(@NonNull SaleDetailsViewHolder saleDetailsViewHolder, int i) {
        Product product = new Product().findProductById(saleDetailList.get(i).idProduct);
        if(product != null){
            saleDetailsViewHolder.txtNameSaleDetailsAdapter.setVisibility(View.VISIBLE);
            saleDetailsViewHolder.txtNameSaleDetailsAdapter.setText(""+product.nameProduct);
        }
        saleDetailsViewHolder.txtIdSaleDetailsAdapter.setText(""+saleDetailList.get(i).idProduct);
        saleDetailsViewHolder.txtQuantitySaleDetailsAdapter.setText(""+saleDetailList.get(i).quantity);
        saleDetailsViewHolder.txtSVSaleDetailsAdapter.setText(""+ Tools.setDecimalFormat().format(saleDetailList.get(i).unitValue));
        saleDetailsViewHolder.txtValuetotSaleDetailsAdapter.setText(""+Tools.setDecimalFormat().format(saleDetailList.get(i).totValue));
        List<String> quantityArray = qArray(saleDetailList.get(i).quantity);
        ArrayAdapter<String> dataAdapter =
                new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, quantityArray);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        saleDetailsViewHolder.spnQuantityProduct.setAdapter(dataAdapter);

    }

    private static List<String> qArray(int quantity){
        List<String> stringsArray = new ArrayList<>();

        for (int i=0;i<quantity;i++){
            stringsArray.add(String.valueOf(i+1));
        }
        return stringsArray;
    }

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

    public void setOnClickListener(View.OnClickListener listener){
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        if(listener != null){
            listener.onClick(v);
        }
    }

    static class SaleDetailsViewHolder extends RecyclerView.ViewHolder {
        TextView txtNameSaleDetailsAdapter;
        TextView txtIdSaleDetailsAdapter;
        TextView txtQuantitySaleDetailsAdapter;
        TextView txtSVSaleDetailsAdapter;
        TextView txtValuetotSaleDetailsAdapter;
        Spinner spnQuantityProduct;

        SaleDetailsViewHolder(View itemView) {
            super(itemView);
            txtNameSaleDetailsAdapter = itemView.findViewById(R.id.txtNameSaleDetailsAdapter);
            txtIdSaleDetailsAdapter = itemView.findViewById(R.id.txtIdSaleDetailsAdapter);
            txtQuantitySaleDetailsAdapter = itemView.findViewById(R.id.txtQuantitySaleDetailsAdapter);
            txtSVSaleDetailsAdapter = itemView.findViewById(R.id.txtSVSaleDetailsAdapter);
            txtValuetotSaleDetailsAdapter = itemView.findViewById(R.id.txtValuetotSaleDetailsAdapter);
            spnQuantityProduct = itemView.findViewById(R.id.spnQuantityProducttoDevolution);
        }

    }

按照本教程解决

https://demonuts.com/android-recyclerview-with-edittext/

当针对我的代码进行修改时,我通过执行此操作并按下按钮访问来获取值:

public void getEditValue(){

        for(int i=0;i<saleDetailList.size();i++)
        {
            View view=rcvMoneyDevolution.getChildAt(i); // This will give you entire row(child) from RecyclerView
            if(view!=null)
            {
                TextView textView= view.findViewById(R.id.txtSVSaleDetailsAdapter);
                Log.e("Tag",textView.getText().toString());
                Spinner mySpinner = view.findViewById(R.id.spnQuantityProducttoDevolution);
                String text = mySpinner.getSelectedItem().toString();
                Log.e("Tag",text);
                String moneyDevolution = MoneyDevolutionAdapter.editModelArrayList.get(i).getEditTextValue();
                Log.e("Tag",moneyDevolution);

            }
        }

    }