如何在andoid中获取ExpandableListView的ChildView项的Id

时间:2016-10-27 05:39:56

标签: android expandablelistview

我使用ExpandapbeListView它的工作完美所有扩展和崩溃,但我只想更新特定的子项目,当我点击加值应该在EditText更新,我不想使用 notifyDatasetChanged()只想更新特定字段,我也应该直接更新EditText。它可以有多个子项。

Ex:高露洁可能有多个子项,如100gm,200gm,300gm

所以,当我点击Plus时,它应该能够获得EditText的Id和更新数量

请帮助我。

enter image description here

 @Override
    public View getChildView(int productPos, int weightPos, boolean b, View plusMinusView, ViewGroup viewGroup) {

        if (plusMinusView == null) {

            csHolder = new ChildHolder();
            LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            plusMinusView = inflater.inflate(R.layout.orders_products_plus_minus_design, null);
        }
        csHolder.minQty             = (TextView) plusMinusView.findViewById(R.id.orderProducts_submitMinQtyTxt);
        csHolder.totalPriceTxt      = (TextView) plusMinusView.findViewById(R.id.orderProducts_submitTotalPriceTxt);
        csHolder.weightTxt          = (TextView) plusMinusView.findViewById(R.id.orderProducts_submitWeightTxt);
        csHolder.unitPrice          = (TextView) plusMinusView.findViewById(R.id.orderProducts_submitUnitPriceTxt);
        csHolder.totalTaxTxt        = (TextView) plusMinusView.findViewById(R.id.orderProducts_submitTotalTaxTxt);
        csHolder.netPriceTxt        = (TextView) plusMinusView.findViewById(R.id.orderProducts_submitNetPriceTxt);
        csHolder.orderQtyEdit       = (CustomEditText) plusMinusView.findViewById(R.id.orderProducts_orderQtyTxt);
        csHolder.plusTxt            = (RelativeLayout) plusMinusView.findViewById(R.id.orderProducts_plusTxtLay);
        csHolder.minusTxt           = (RelativeLayout) plusMinusView.findViewById(R.id.orderProducts_minusTxtLay);


        plusMinusView.setTag(productPos + "_" + weightPos);

        String tag = "weight_" + productPos + "_" + weightPos;
        csHolder.orderQtyEdit.setTag(tag);
        csHolder.plusTxt.setTag(tag);
        csHolder.minusTxt.setTag(tag);


        //csHolder.plusTxt.setOnClickListener(weightClick);
        //csHolder.minusTxt.setOnClickListener(weightClick);

        final View finalPlusMinusView = plusMinusView;
        csHolder.plusTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              csHolder.orderQtyEdit.setText("5");
            }
        });

        if(!csStatus.equalsIgnoreCase("DRAFT")) {
            csHolder.plusTxt.setVisibility(View.GONE);
            csHolder.minusTxt.setVisibility(View.GONE);
            csHolder.orderQtyEdit.setEnabled(false);
        }
        else
        {
            csHolder.plusTxt.setVisibility(View.VISIBLE);
            csHolder.minusTxt.setVisibility(View.VISIBLE);
            csHolder.orderQtyEdit.setEnabled(true);
        }

        try
        {
            csHolder.orderQtyEdit.addTextChangedListener(new MyTextWatcher(csHolder.orderQtyEdit));

            JSONObject weighObj = csMainArr.getJSONObject(productPos).getJSONArray("weights").getJSONObject(weightPos);
            if(weighObj.has("unit"))
            {
                csHolder.weightTxt.setText(weighObj.getString("unit"));
            }

            if (weighObj.has("order_qty") == false)
                weighObj.put("order_qty", "0");

            if (weighObj.has("sell_price") == false)
                weighObj.put("sell_price", "0");

            if (weighObj.has("order_qty") == false)
            {
                csHolder.totalPriceTxt.setText("0.00");
                csHolder.totalTaxTxt.setText("0.00");
                csHolder.netPriceTxt.setText("0.00");
            }
            else {
                int         qty         = 0;
                double      sellPrice   = 0.00;
                float       tax         = 0f;

                double   totalPrice  = 0.00;
                double   totalTax    = 0.00;
                double   netPrice    = 0.00;
                if(csStatus.equals("DRAFT")) {
                    qty = Integer.parseInt(weighObj.getString("order_qty"));
                    sellPrice = weighObj.getDouble("sell_price");
                }
                else
                {
                    qty = Integer.parseInt(weighObj.has("qty") ? weighObj.getString("qty"):"0");
                    sellPrice = weighObj.getDouble("unit_price");
                }
                tax         = Float.parseFloat(csMainArr.getJSONObject(productPos).has("tax") ? csMainArr.getJSONObject(productPos).getString("tax") : "0");


                totalPrice  = qty*sellPrice;
                totalTax    = (totalPrice*tax)/100;
                netPrice    = totalPrice + totalTax;

                csHolder.totalPriceTxt.setText(getResources().getString(R.string.Rs)+" "+String.format("%.2f",totalPrice));
                csHolder.totalTaxTxt.setText(getResources().getString(R.string.Rs)+" "+String.format("%.2f",totalTax));
                csHolder.netPriceTxt.setText(getResources().getString(R.string.Rs)+" "+String.format("%.2f",netPrice));
            }

            csHolder.orderQtyEdit.isValueChangeMySelf = true;
            if(csStatus.equals("DRAFT"))
                csHolder.orderQtyEdit.setText(weighObj.getString("order_qty"));
            else
                csHolder.orderQtyEdit.setText(weighObj.has("qty")?weighObj.getString("qty"):"0");

            /*if(weightPos == iClickedItem) {
                csHolder.orderQtyEdit.requestFocus();

            }
            else {
                csHolder.orderQtyEdit.clearFocus();
            }*/

            if(csStatus.equals("DRAFT"))
                csHolder.unitPrice.setText(getResources().getString(R.string.Rs)+" "+String.format("%.2f",weighObj.has("sell_price")?weighObj.getDouble("sell_price") : 0.00));
            else
                csHolder.unitPrice.setText(getResources().getString(R.string.Rs)+" "+String.format("%.2f",weighObj.has("unit_price")?weighObj.getDouble("unit_price") : 0.00));

            csHolder.minQty.setText(weighObj.has("min_order_qty")?weighObj.getString("min_order_qty"):"0");


            //View line = (View) plusMinusView.findViewById(R.id.orderProducts_submitDividerLine);
            //if(isLast)
            //  line.setVisibility(View.GONE);

        }
        catch(Exception e)
        {

        }


        return plusMinusView;
    }

0 个答案:

没有答案