2012-06-29 17 views
1

我已經使用自定義適配器和佈局項目實現了列表視圖。 因爲我有一個複雜的邏輯。當listview首先加載它時,它顯示正確的記錄與我的邏輯。 但是,當我向下滾動,比它改變了我的邏輯含義和更新數據。在列表視圖中運行代碼getitem

所以我想運行的邏輯只有一次,當列表視圖綁定..

誰能幫助我?

在此先感謝。

+0

在ListView滾動可以使項目得到重新創建,如果你錯誤地實現你的'getView'方法,它可能會有不需要的結果。請提供一些代碼,以便我們可以進一步幫助您。 –

回答

0
public View getView(final int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
    final ViewHolder holder; 

    if (convertView == null) { 
     holder = new ViewHolder(); 

     convertView = mInflater.inflate(R.layout.shopping_cartcell_layout, 
       null); 
     holder.product_name = (TextView) convertView 
       .findViewById(R.id.product_name); 
     holder.base_price_tv = (TextView) convertView 
       .findViewById(R.id.base_price_view); 



     convertView.setTag(holder); 

    } else { 
     holder = (ViewHolder) convertView.getTag(); 

    } 

    // here you can set your value to your view one example like below 
      // if you have any arrylist then get your data and set to your view 
      // for example "PRODUCTLIST" is your array list in which you store products 
      // see how to set it 

     if(PRODUCTLIST.get(position).getproductname !=null){ 

       holder.product_name.settext(PRODUCTLIST.get(position).getproductname); 
       } 

     if(PRODUCTLIST.get(position).getproductbaseprice !=null){ 

      holder.base_price_tv.settext(PRODUCTLIST.get(position).getproductbaseprice); 

      } 
     return convertView; 
相關問題