2012-03-22 10 views
0

HI Guyz baseadapterを使ってセクションのカスタムリストビューを作成しましたが、うまくいきましたが、もう一度スクロールすると1つの問題が発生し、クラッシュして例外が発生します。私はposview私のgetview()コードplz私を助ける。Sectioned Listviewメモリ出力の問題

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    View row = convertView; 

    Image cached = images[position]; 
    boolean flag = cached.sender_user; 
    // System.out.println("Timeline: Position: "+position+", Length: "+data.length); 
    // if(position!=data.length-1){ 
    System.out.println(position + " ===== " + images[position].pic_url); 

    if (cached.sender_user == false) { 
     System.out.println("If"); 

     row = vi.inflate(R.layout.list_row_layout_sender, null); 
     txt_msg = (TextView) row.findViewById(R.id.txt_msg); 
     txt_name = (TextView) row.findViewById(R.id.txt_name); 
     txt_time = (TextView) row.findViewById(R.id.txt_time); 
     img = (ImageView) row.findViewById(R.id.user_img); 


     btn_loc=(Button)row.findViewById(R.id.btn_loc); 
     btn_loc.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       System.out.println("-------------- btn_loc ------------------- Sender"); 
       Developer.callIntent_userlocation(context, "18.50929796 ", "73.79045371"); 
      } 
     }); 
     txt_name.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       System.out.println("----Name----"); 

       Developer.callIntent(context,images[position].id); 
      } 
     }); 
     img.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       System.out.println("----Image----"); 
       Developer.callIntent(context,images[position].id); 
      } 
     }); 
     txt_name.setText(cached.sender_name); 
     txt_time.setText(cached.time); 
     txt_msg.setText(cached.messege); 
     if (position != 0) { 
      cached = images[position - 1]; 
      if (cached.sender_user == flag) { 
       img.setVisibility(ImageView.INVISIBLE); 
       txt_name.setVisibility(TextView.INVISIBLE); 
      } else 
       imageLoader.DisplayImage(images[position].pic_url.trim() 
         .replace(" ", "%20"), 
         ReadMessageActivityNew.activity, img); 
     } else 
      imageLoader.DisplayImage(images[position].pic_url.trim() 
        .replace(" ", "%20"), ReadMessageActivityNew.activity, 
        img); 
     System.out.println("Downloading=> for Reciver" + cached.pic_url); 
     return row; 
    } 

    else { 

     System.out.println("Else"); 

     row = vi.inflate(R.layout.list_row_layout_receiver, parent, false); 
     txt_msg = (TextView) row.findViewById(R.id.txt_msg); 
     txt_name = (TextView) row.findViewById(R.id.txt_name); 
     txt_time = (TextView) row.findViewById(R.id.txt_time); 
     img = (ImageView) row.findViewById(R.id.user_img); 
     btn_loc=(Button)row.findViewById(R.id.btn_loc); 

     btn_loc.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       System.out.println("-------------- btn_loc ------------------- Reciever"); 


       Developer.callIntent_userlocation(context, "18.50929796 ", "73.79045371"); 
      } 
     }); 
     txt_name.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Developer.callIntent(context, images[position].id); 
      } 
     }); 
     img.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 


       Developer.callIntent(context, images[position].id); 
      } 
     }); 
     txt_name.setText("Me"); 
     txt_time.setText(cached.time); 
     txt_msg.setText(cached.messege); 
     if (position != 0) { 
      cached = images[position - 1]; 
      if (cached.sender_user == flag) { 
       img.setVisibility(ImageView.INVISIBLE); 
       txt_name.setVisibility(TextView.INVISIBLE); 
      } else 
       imageLoader.DisplayImage(images[position].pic_url.trim() 
         .replace(" ", "%20"), 
         ReadMessageActivityNew.activity, img); 
     } else 
      imageLoader.DisplayImage(images[position].pic_url.trim() 
        .replace(" ", "%20"), ReadMessageActivityNew.activity, 
        img); 

     System.out.println("Downloading=> for User" + cached.pic_url); 
     return row; 
    } 

} 

答えて

1

問題は、このメソッドが呼び出されるたびに新しいビューを作成することです。 convertViewがnullの場合は、レイアウトからビューを展開するだけで済みます。 convertViewがnullでない場合は、リサイクルされたビューです。

+0

セクション別リストビューの例を教えてください – GTID