您的位置:首页 > 移动开发 > Android开发

Android ListView中的EditText 动态更新数据源 SimpleAdapter (二)

2018-03-21 10:02 435 查看
更改数据源后要先使用
adapter.notifyDataSetChanged();刷新数据
public void FlushPrice(){
ListView list= (ListView)findViewById(R.id.act_setorder_foodListView);//获得listview
for (int i = 0; i < list.getChildCount(); i++) {
LinearLayout layout = (LinearLayout)list.getChildAt(i);// 获得子item的layout
TextView textView = (TextView) layout.findViewById(R.id.Text_one_name) ;
EditText et = (EditText) layout.findViewById(R.id.editText_one_price);// 从layout中获得控件,根据其id
for (GoodsItem goodsItem :goodsItemList) {
if (textView.getText().equals(goodsItem.name)) {
goodsItem.reall_price = Double.parseDouble(String.valueOf(et.getText()));
}
}
}
all_money = 0;
for (GoodsItem goodsList : goodsItemList) {
all_money+= goodsList.count*goodsList.reall_price;
all_price+= goodsList.count*goodsList.price;
}
price.setText(String.valueOf(all_money));
personalList.clear();
personalList1.clear();
for (GoodsItem goodsList : goodsItemList) {
Map<String,Object> map=new HashMap<String,Object>();
map.put("name",goodsList.name);
map.put("number",goodsList.count+goodsList.product_units);
map.put("one_price",goodsList.reall_price);
personalList1.add(map);
}
personalList.addAll(personalList1);
adapter.notifyDataSetChanged();
}
这样就可以实现动态更新数据源了,因为每一个item有区分,所有超出屏幕范围外的item也可以更新数据了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息