最近 做购物车的时候 ,遇到几个问题,现在 总结如下:
1:不让listview复用组件(购物车,或者有特殊操作的时候):
自己保存所有的view对象
public View getView(final int position, View convertView, ViewGroup parent) { final DaydayCouponBean bean = list.get(position); <span style="color:#ff0000;">View view = DataCenter.shoppingCarMap.get(new Integer(position));</span> <strong>if (view == null) { convertView = LayoutInflater.from(context).inflate(R.layout.daydaycoupon_shoppingcar_item, null); DataCenter.shoppingCarMap.put(position, convertView); } else { convertView = DataCenter.shoppingCarMap.get(new Integer(position)); }</strong> return view; }
<strong>public static TreeMap<Integer, View> shoppingCarMap = new TreeMap<Integer, View>();</strong>
2:scrowvdiw嵌套lsitview 高度无法计算 每次更新数据集Arraylist之后,手动计算lsitview的高度,所有的item就都会初始化
或者 购物车 要 一次性 初始化所有的 item(如 获取所有的商品总额,不是当前页吗可见区域的总额)
<span style="font-size:14px;"> adapter.notifyDataSetChanged(); float density = getResources().getDisplayMetrics().density; // 屏幕密度(0.75 / 1.0 / 1.5) <strong> UIUitls.setListViewHeightBasedOnChildren(listView, (int) (density * 20));</strong></span>
http://ryanjoy.iteye.com/blog/1291331
注意,在使用listview嵌套listview发现,计算的高度还是比较诡异,解决办法??要使用自定义的listview
/** * Created by david on 2014/6/30. * 解决lsitview 嵌套 listveiw 高度计算错误,使用的lsitview */ public class MyListview extends ListView { public MyListview(Context context) { super(context); } public MyListview(Context context, AttributeSet attrs) { super(context, attrs); } public MyListview(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { <strong> int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);</strong> super.onMeasure(widthMeasureSpec, expandSpec); } }每次重新刷新lsitrview的时候
UIUitls.setListViewHeightBasedOnChildren(listView, DensityUtil.dip2px(120),beans.size() ); adapter.notifyDataSetChanged();
android购物车遇到的问题,布布扣,bubuko.com
原文:http://blog.csdn.net/ab601026460/article/details/36951979