始终从膨胀的布局获得相同的值

时间:2014-07-22 05:31:03

标签: android android-layout android-inflate

我按下按钮点击一个布局,就像点击按钮一样多,这个布局有edittexts,我想把所有的值都放到hashmap中,但是所有的时间我都得到了第一个到hashmap的值,Loop是运行布局数量多少次,但是所有时间都只从第一个布局获取值,我的代码如下,请帮帮我吧 的

ArrayList<ViewGroup> listOfViewGroups;
LinearLayout listitems;
onCreate(){
listitems = (LinearLayout) findViewById(R.id.ll_list);
listOfViewGroups = new ArrayList<ViewGroup>();
et_item_id = (EditText) addView.findViewById(R.id.et_item_id);
        et_desc = (EditText) addView.findViewById(R.id.et_desc);
        et_qty = (EditText) addView.findViewById(R.id.et_qty);
        et_unit_prize = (EditText) addView.findViewById(R.id.et_unit_prize);
        et_amt = (EditText) addView.findViewById(R.id.et_amt);

        buttonRemove.setVisibility(View.GONE);
        et_qty.addTextChangedListener(textwatcher);
        et_unit_prize.addTextChangedListener(textwatcher);

        listitems.addView(addView);

        listOfViewGroups.add(listitems);

add.setOnClickListener(new OnClickListener)){
@Override
onClick(){
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View addView = layoutInflater.inflate(R.layout.raw_descs, null);
            ImageView buttonRemove = (ImageView) addView.findViewById(R.id.iv_del);
            et_item_id = (EditText) addView.findViewById(R.id.et_item_id);
            et_desc = (EditText) addView.findViewById(R.id.et_desc);
            et_qty = (EditText) addView.findViewById(R.id.et_qty);
            et_unit_prize = (EditText) addView.findViewById(R.id.et_unit_prize);
            et_amt = (EditText) addView.findViewById(R.id.et_amt);

            et_qty.addTextChangedListener(textwatcher);
            et_unit_prize.addTextChangedListener(textwatcher);
listitems.addView(addView);
            listOfViewGroups.add(listitems);
}

}
    public String urlgenerater() {

            String paramPass = null;

            // get each ViewGroup
            for (int i = 0; i < listOfViewGroups.size(); i++) {
                ViewGroup vg = listOfViewGroups.get(i);
                // get each EditText containing the amount
                EditText item_id = (EditText) vg.findViewById(R.id.et_item_id);
                EditText desc = (EditText) vg.findViewById(R.id.et_desc);
                EditText unitprice = (EditText) vg.findViewById(R.id.et_unit_prize);
                EditText qty = (EditText) vg.findViewById(R.id.et_qty);
                // get the string entered in the EditText
                // change to a double
                System.out.println(":::::::::::::::::::::::::::::ITEM _ID:::::::::::::::::::::;;" + item_id.getText().toString());
                System.out.println("::::::::::::::::::::::::::::DESCRIPTION:::::::::::::::::::;;" + desc.getText().toString());
                System.out.println(":::::::::::::::::::::::::::::UNIT PRICE::::::::::::::::::::;;" + unitprice.getText().toString());
                System.out.println("::::::::::::::::::::::::::::QUANTITY:::::::::::::::::::::;;" + qty.getText().toString());

                descMap = new HashMap<String, String>();
                descMap.put("item", item_id.getText().toString());
                descMap.put("up", unitprice.getText().toString());
                descMap.put("desc", desc.getText().toString());
                descMap.put("qty", qty.getText().toString());

                System.out.println("::::::::::::::::::MAP VALUES::::::::::" + descMap);

                descList.add(descMap);

                paramPass = paramPass + "&item_name[" + i + "]=" + item_id.getText().toString() + "&qty[" + i + "]=" + qty.getText().toString() + "&desc[" + i + "]=" + desc.getText().toString()
                        + "&unit_price[" + i + "]=" + unitprice.getText().toString();

            }

            return paramPass;
        }
    }

0 个答案:

没有答案