Why do items disappear when I scroll the listView?

前端 未结 2 1481
南笙
南笙 2020-12-05 10:55

My application use a ListView which display different items in the cell. it must have photo and name, but it happens to have description and icons.

The

相关标签:
2条回答
  • 2020-12-05 11:25

    I had the same problem.

            if (!imageuri.isEmpty()) {
                rl.setVisibility(View.VISIBLE);
                SmartImageView imageView = (SmartImageView) view.findViewById(R.id.detailimageView1);
                imageView.setImageUrl(imageuri);
            } else {            
                rl.setVisibility(View.GONE);
            }
    

    Thanks for the solution!

    0 讨论(0)
  • 2020-12-05 11:36

    It's because you're hiding some of your views sometimes, and you never show them again. Example:

            if (!(datapark.get(position).bio.equals(""))){          
              holder.bio.setText(datapark.get(position).bio);
            }else{
              ((TextView)convertView.findViewById(R.id.bio)).setVisibility(View.GONE);
            }
    

    instead try:

            if (!(datapark.get(position).bio.equals(""))){ 
              holder.bio.setVisibility(View.VISIBLE);         
              holder.bio.setText(datapark.get(position).bio);
            }else{
              holder.bio.setVisibility(View.GONE);
            }
    

    Remember that views are recycled, so, unless you show the views the next time you return one, they will never be visible again. Also, remember that holder.bio is the same thing that is returned by the findViewById, so you can do holder.bio.setVisibility(View.GONE) in the else block.

    0 讨论(0)
提交回复
热议问题