2012-05-31 59 views
0

我已經做了一個應用程序,我在服裝gridview顯示數據,它的進展順利,但問題是,當我滾動它,併到底部並返回頂部,那麼所有項目的位置可以自動更改.and一段時間後它不會出現後scroll.here是我的代碼,我認爲有些事情錯getView錯誤的gridview

@

Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     ViewHolder viewholder; 
     // LayoutInflater inflator = activit.getLayoutInflater(); 



     if(convertView == null) { // recycled view is null so create it. 
      viewholder = new ViewHolder(); 
     convertView = inflator.inflate(R.layout.griedviewrow, null); 

     viewholder.imgvGridItem = (RelativeLayout) convertView 
       .findViewById(R.id.rlGreidItemicon); 
     viewholder.txtGridItemlabel = (TextView) convertView 
       .findViewById(R.id.txtGridItemlabel); 

      if ((lstpinfo.get(position).appname.toString()) != null) { 

       viewholder.imgvGridItem.addView(getimageviewimage(lstpinfo 
         .get(position).icon)); 
       viewholder.txtGridItemlabel 
         .setText(lstpinfo.get(position).appname.toString()); 

      } 
     } 

     return convertView; 

    } 

回答

0

長相轉換視圖邏輯還沒有完全實現。

當你滾動時,你會得到非空的convertView,那時你需要設置新的數據,並且你在這種情況下什麼都不做....... +你沒有在標籤中設置ViewHolder從convertView中取回它並使用它。

@Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      System.out.println("getView " + position + " " + convertView); 
      ViewHolder holder = null; 

       if (convertView == null) { 
       convertView = mInflater.inflate(R.layout.item1, null); 
       holder = new ViewHolder(); 
       holder.textView = (TextView)convertView.findViewById(R.id.text); 
       convertView.setTag(holder); 
      } else { 
       holder = (ViewHolder)convertView.getTag(); 
      } 

     holder.textView.setText(mData.get(position));//<========== see it ..... 
      return convertView; 
     } 

    }