0

in below getView method i am loading image in imageview. if some rows have not any image then imageview's visibility will gone. i have put condition for that. now my problem is that while scrolling in listview some rows with images is automatically hide imageview and some rows have not any image that can get those image.

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder = null;

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

        convertView = LayoutInflater.from(context).inflate(R.layout.list_items_exhibition, null);

        holder.img = (ImageView) convertView.findViewById(R.id.img);

        convertView.setTag(holder);

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

    DataBean bean = (DataBean) list.get(position);

    if( bean.getImgUrl() == null ){
        holder.img.setVisibility(View.GONE);
    } else {
        imageloader.displayImage(bean.getImgUrl(), holder.img, option);
    }
}

kindly ignore my grammatical mistake in English.

Bhavesh Rangani
  • 1,490
  • 12
  • 23

3 Answers3

1

Again Set Visibility for ImageView

if( bean.getImgUrl() == null ){
    holder.img.setVisibility(View.GONE);
} else {
    holder.img.setVisibility(View.VISIBLE); //Add this line
    imageloader.displayImage(bean.getImgUrl(), holder.img, option);
}
1

You should change thé visibilité back to View.VISIBLE when you assigh an image to thé ImageView.

0

You should use both getViewTypeCount() and getItemViewType(int position) in your adapter to handle listview having image in some rows only,, simple setVisibility(View.VISIBLE) wont work in your case because android caches your images after getting loaded

In your case getViewTypeCount() should return '2' , because you are telling android there are two types of rows that needs to be cached separately and in the getItemViewType(int position) you tell what are those two types

Like

if(bean.getImgUrl() == null){
    return 0;
}else{
    return 1;
}

Refer this solution for more details

Community
  • 1
  • 1
Ujju
  • 2,723
  • 3
  • 25
  • 35