我按下按钮点击一个布局,就像点击按钮一样多,这个布局有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;
}
}