android購物車遇到的問題

來源:互聯網
上載者:User

標籤: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();



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.