0

All

I am new to Android , If i ask a question in bad manner please inform me so i will take care of that next time.

My Question :

I create Listview , In that list views each row has three elements .

1) ImageView : which display (URL and i convert in Bitmap)
2) Name : Text
3) Address : Text

I successfully created that row but i face one small issue

++++> First when all rows are displayed at that time i am not able to see that Image of every Row . and when i scroll that list then once i can see that images.

help me if any one face this issue.

Code

BaseAdapter class :

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

LayoutInflater mInflater = (LayoutInflater) context
        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
    convertView = mInflater.inflate(
            R.layout.mention_timeline_listitems, null);
    holder = new ViewHolder();
    holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
    holder.imageView = (ImageView) convertView.findViewById(R.id.icon);

    convertView.setTag(holder);

    rowItem = (mentionRowItems) getItem(position);

    holder.txtTitle.setText(rowItem.getTitle());

    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                holder.imageView.setImageBitmap(common
                        .imageLoad(rowItem.getImageId()));
            } catch (Exception ex) {
                Log.d("Error------->", ex + "");
            }
        }
    });

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

return convertView;

}

rowFile code

    for(loop){ // 4 times
    rowItems.add(new mentionRowItems(profile_bg_url, name,
                            screen_name));

Example .. profile_bg_url = "https://dl.dropboxusercontent.com/u/72783403/AtoZ/1.png";
Example .. screen_name = "Admin"

    }

                adapter = new mentionBaseAdapter(getActivity(), rowItems);
listView.setAdapter(adapter);

Thanks,
Dharmik

Dharmik Patel
  • 76
  • 1
  • 11

3 Answers3

1

Dharmik, you can use picasso http://square.github.io/picasso/ for loading the image.

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


    LayoutInflater mInflater = (LayoutInflater) context
        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
        convertView = mInflater.inflate(
            R.layout.mention_timeline_listitems, parent, false);
        holder = new ViewHolder();
        holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
        holder.imageView = (ImageView) convertView.findViewById(R.id.icon);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    rowItem = (mentionRowItems) getItem(position);
    holder.txtTitle.setText(rowItem.getTitle());

    String imageUrl =  rowItem.profile_bg_url.; // image url
    Picasso.with(context).load(imageUrl).into(holder.imageView);
}
gvlasov
  • 18,638
  • 21
  • 74
  • 110
Gaurav Vashisth
  • 7,547
  • 8
  • 35
  • 56
1

please post your code,it may in your Adapter class,which in the getView() method,Please use View holder pattern to preventing duplication of row

 @Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null || !(convertView.getTag() instanceof ViewHolder)) {
  convertView =
      LayoutInflater.from(context).inflate(R.layout.list_item_conversation, parent, false);
  holder = new ViewHolder();
  holder.content = (TextView) convertView.findViewById(R.id.conversation_content);
  holder.masterPhoto =
      (MasterAvatarView) convertView.findViewById(R.id.conversation_photo_master);
  holder.masterPhoto.setDefaultImageResId(R.drawable.default_avatar_small);
  holder.userPhoto = (MasterAvatarView) convertView.findViewById(R.id.conversation_photo_user);
  holder.userPhoto.setDefaultImageResId(R.drawable.default_avatar_small);
  holder.itemLayout = (LinearLayout) convertView.findViewById(R.id.conversation_item);
  holder.time = (TextView) convertView.findViewById(R.id.conversation_time);
  convertView.setTag(holder);
} else {
  holder = (ViewHolder) convertView.getTag();
}
....................
lgw150
  • 170
  • 1
  • 3
  • 13
0

you should set your Views data out side the body of if(convertView == null). For your help replace your getView() method with below one

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

    LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(
                R.layout.mention_timeline_listitems, null);
        holder = new ViewHolder();
        holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
        holder.imageView = (ImageView) convertView.findViewById(R.id.icon);

        convertView.setTag(holder);


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

rowItem = (mentionRowItems) getItem(position);

        holder.txtTitle.setText(rowItem.getTitle());

        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                try {
                    holder.imageView.setImageBitmap(common
                            .imageLoad(rowItem.getImageId()));
                } catch (Exception ex) {
                    Log.d("Error------->", ex + "");
                }
            }
        });

        thread.start();

    return convertView;
    }

Hope it will help you.

Zubair Ahmed
  • 2,857
  • 2
  • 27
  • 47
  • Then you need research in `listview` recycling and `ImageCache and Bitmap` to display in `adapter`. For detail of `listView` recycling follow this link http://stackoverflow.com/a/14108676/2311051 And for Caching Images and bitmap follow my answer here http://stackoverflow.com/a/23487962/2311051 – Zubair Ahmed Aug 12 '14 at 08:26