標籤:android style blog http java color
最近 做購物車的時候 ,遇到幾個問題,現在 總結如下:
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; }
對應的Map
<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>
3:listview嵌套問題詳細見:
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();