Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RecyclerView Textwatcher值不起作用_Android_Android Recyclerview_Textwatcher - Fatal编程技术网

Android RecyclerView Textwatcher值不起作用

Android RecyclerView Textwatcher值不起作用,android,android-recyclerview,textwatcher,Android,Android Recyclerview,Textwatcher,我正在从事一个android应用程序项目,其中我有3个edittext。这3个编辑文本输入数量、单价和总金额。基本计算是用户输入量,然后用户可以输入总价或单价。如果有人输入单价,则计算结果将为体积*单价,并以总金额文本打印。此外,如果有人输入toal,则计算结果将为total/volume,并以单价文本打印该值。这部分工作正常,但这只发生在最后一张recyclerview卡上,而不是上面的卡上。这是我的密码 textWatcher =new TextWatcher() { @Ov

我正在从事一个android应用程序项目,其中我有3个edittext。这3个编辑文本输入数量、单价和总金额。基本计算是用户输入量,然后用户可以输入总价或单价。如果有人输入单价,则计算结果将为体积*单价,并以总金额文本打印。此外,如果有人输入toal,则计算结果将为total/volume,并以单价文本打印该值。这部分工作正常,但这只发生在最后一张recyclerview卡上,而不是上面的卡上。这是我的密码

textWatcher =new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable != null && !editable.toString().equalsIgnoreCase("")){
                if (holder.item_total_value_tv.getText().hashCode()==editable.hashCode()){
                        holder.crop_unit_price_et.setEnabled(false);
                        if (editable.toString().isEmpty()) {
                            totalAmount = 0;
                        } else {
                            totalAmount = Double.parseDouble(editable.toString());
                        }

                        cropSelectedItemList.get(position).setTotalAmount((float) totalAmount);

                        if (cropSelectedItemList.get(position).getVolume() == 0){
                            totalAmount=0;
                            unitPrice=0;
                        }
                        else{
                            unitPrice=cropSelectedItemList.get(position).getTotalAmount()/cropSelectedItemList.get(position).getVolume();
                            holder.crop_unit_price_et.removeTextChangedListener(textWatcher);
                            cropSelectedItemList.get(position).setUnitPrice(unitPrice);
                            holder.crop_unit_price_et.setText(String.format(Locale.US,"%.2f",unitPrice));
                            holder.crop_unit_price_et.addTextChangedListener(textWatcher);
                        }

                        System.out.println("tv1 Volume: "+cropSelectedItemList.get(position).getVolume());
                        System.out.println("tv1 Total :" +cropSelectedItemList.get(position).getTotalAmount());
                        System.out.println("tv1 Uni Price: "+unitPrice);
                }

                else if (holder.crop_volume_et.getText().hashCode() == editable.hashCode()){
                    if (editable.toString().isEmpty()) {
                        volume = 0;

                    } else {
                        volume = Double.parseDouble(editable.toString());
                    }

                    cropSelectedItemList.get(position).setVolume((float) volume);

                    if(cropSelectedItemList.get(position).getVolume()==0){
                        unitPrice=0;
                        totalAmount=0;
                    }

                }

                else if (holder.crop_unit_price_et.getText().hashCode() == editable.hashCode()){
                    holder.item_total_value_tv.setEnabled(false);
                    if (editable.toString().equals("")){
                        unitPrice=0;
                    }
                    else {
                        unitPrice=Double.parseDouble(editable.toString());
                    }

                    cropSelectedItemList.get(position).setUnitPrice((float) unitPrice);

                    if (cropSelectedItemList.get(position).getVolume()==0){
                        totalAmount=0.0;
                        unitPrice=0.0;
                    }
                    else{
                        totalAmount = cropSelectedItemList.get(position).getVolume() * cropSelectedItemList.get(position).getUnitPrice();
                        holder.item_total_value_tv.removeTextChangedListener(textWatcher);
                        cropSelectedItemList.get(position).setTotalAmount(totalAmount);
                        holder.item_total_value_tv.setText(String.format(Locale.US,"%.2f",totalAmount));
                        holder.item_total_value_tv.addTextChangedListener(textWatcher);
                    }

                System.out.println("tv3 Volume: "+cropSelectedItemList.get(position).getVolume());
                System.out.println("tv3 Unit Price: "+cropSelectedItemList.get(position).getUnitPrice());
                System.out.println("tv3 total: "+totalAmount);

                }

                else {
                    Log.e("Hihasan","Something Went Wrong");
                }
            }
        }
    };

holder.item_total_value_tv.addTextChangedListener(textWatcher);
    holder.crop_volume_et.addTextChangedListener(textWatcher);
    holder.crop_unit_price_et.addTextChangedListener(textWatcher);

你的意思是它只对recyclerView的最后一项有效?如果是这样,那么试着为我已经做过的每个editTextI定义不同的单独TextWatcher,结果是一样的