Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7704827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:46:07+00:00 2026-05-31T23:46:07+00:00

when we scroll down or up getview problem? getview not called properly? at background

  • 0

when we scroll down or up getview problem?
getview not called properly?
at background images are loading from respective url?
layout is different for sender and receiver..

public class NewReadMessageAdapter extends BaseAdapter {
private Context context;

private LayoutInflater vi;
public ImageLoader imageLoader;
private Typeface tf;

private class Image {
    String pic_url = new String();
    Bitmap thumb;
    String messege = new String();
    int id;
    String time = new String();
    String sender_name = new String();
    public boolean sender_user;

}


private Image[] images;
ArrayList<Messages> messages = new ArrayList<Messages>();

private TextView txt_msg;

private TextView txt_name;

private TextView txt_time;
Button btn_loc;
private ImageView img;

 private ArrayList<Messages> mData = new ArrayList<Messages>();
 private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();
 private static final int TYPE_RECEIVER = 0;
 private static final int TYPE_SENDER = 1;
public NewReadMessageAdapter(Context context,
        ReadMessagePostParser messageParser, String sender_id,
        String reciever_id) {

    this.context = context;

    tf = Typeface.createFromAsset(context.getAssets(), "fonts/tahoma.ttf");
    messages = messageParser.getMessages();
    imageLoader = new ImageLoader(context.getApplicationContext());
    images = new Image[messages.size()];
    for (int i = 0, j = messages.size(); i < j; i++) {
        images[i] = new Image();
        images[i].messege = messages.get(i).getMessage_text();

        images[i].time = messages.get(i).getTime();
        if (messages.get(i).getMessage_from().equals("YES")) {
            images[i].sender_name = messageParser.sender_name;
            images[i].pic_url = messageParser.sender_pic_url;
            images[i].sender_user = true;
            images[i].id = Integer.parseInt(sender_id);


        } else {
            images[i].sender_user = false;
            images[i].id = Integer.parseInt(reciever_id);
            images[i].sender_name = messageParser.reciever_name;
            images[i].pic_url = messageParser.receiver_pic_url;

        }
    }

    for (int i = 0; i < images.length; i++) {
        System.out.println(images[i].pic_url + " " + images[i].sender_name
                + " " + images[i].messege);
    }
    vi = LayoutInflater.from(context);
    imageLoader = new ImageLoader(context.getApplicationContext());

}
public void addItem(final Messages item) {
    mData.add(item);
    notifyDataSetChanged();
}

public void addSeparatorItem(final Messages item) {
    mData.add(item);

    mSeparatorsSet.add(mData.size() - 1);
    notifyDataSetChanged();
}
@Override

public int getCount() {

    return mData.size();
}

@Override

public Object getItem(int position) {

    return mData.get(position);
}

@Override

public long getItemId(int position) {
    return position;
}
 @Override
 public int getItemViewType(int position) {
     return mSeparatorsSet.contains(position) ? TYPE_SENDER : TYPE_RECEIVER;
 }

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

        ViewHolder holder = null;
        int type = getItemViewType(position);

        if (convertView == null) {

            switch (type) {
                case TYPE_SENDER:

                    System.out.println("Sender");
                    holder = new ViewHolder();
                    convertView = vi.inflate(R.layout.list_row_layout_sender, null);
                    holder.txt_msg = (TextView) convertView
                            .findViewById(R.id.txt_msg);
                    holder.txt_name = (TextView) convertView
                            .findViewById(R.id.txt_name);
                    holder.txt_time = (TextView) convertView
                            .findViewById(R.id.txt_time);
                    holder.img = (ImageView) convertView
                            .findViewById(R.id.user_img);
                    holder.btn_loc = (Button) convertView
                            .findViewById(R.id.btn_loc);
                    convertView.setTag(holder);
                    break;
                case TYPE_RECEIVER:
                    System.out.println("Receiver");
                    convertView = vi.inflate(R.layout.list_row_layout_receiver, null);
                    holder = new ViewHolder();
                    holder.txt_msg = (TextView) convertView
                            .findViewById(R.id.txt_msg);
                    holder.txt_name = (TextView) convertView
                            .findViewById(R.id.txt_name);
                    holder.txt_time = (TextView) convertView
                            .findViewById(R.id.txt_time);
                    holder.img = (ImageView) convertView
                            .findViewById(R.id.user_img);
                    holder.btn_loc = (Button) convertView
                            .findViewById(R.id.btn_loc);
                    convertView.setTag(holder);
                    break;
            }

        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.btn_loc.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                System.out
                        .println("-------------- btn_loc ------------------- Sender");
                Developer.callIntent_userlocation(context, "18.50929796 ",
                        "73.79045371");
            }
        });
        holder.txt_name.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                System.out.println("----Name----");

            }
        });
        holder.img.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                System.out.println("----Image----");

            }
        });
        holder.txt_name.setText(mData.get(position).message_from);
        holder.txt_time.setText(mData.get(position).time);
        holder.txt_msg.setText(mData.get(position).message_text);
        if (position != 0) {
            cached = images[position - 1];
            if (cached.sender_user == flag) {
                holder.img.setVisibility(ImageView.INVISIBLE);
                holder.txt_name.setVisibility(TextView.INVISIBLE);
            } else
                imageLoader.DisplayImage(images[position].pic_url.trim()
                        .replace(" ", "%20"), ReadMessageActivityNew.activity,
                        holder.img);
        } else
            imageLoader.DisplayImage(
                    images[position].pic_url.trim().replace(" ", "%20"),
                ReadMessageActivityNew.activity, holder.img);

        return convertView;
    }
static class ViewHolder {
    TextView txt_msg;
    TextView txt_name;
    TextView txt_time;
    ImageView img;
    Button btn_loc;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:46:08+00:00Added an answer on May 31, 2026 at 11:46 pm

    It is better to reuse convertView only when both the layouts are the same. As the layouts are different here, when you reuse a convertView used by sender for receiver, then the view may not be as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I read that there is a software called WinCalibra (scroll a bit down)
This is my AsyncTask, called from getView of an adapter: class LoadImage extends AsyncTask<Object,Void,String>{
i have a listview that displays images from a directory and it is loading
I can not scroll down the screen to view the data in the Replied
I want to smoothly scroll down. I do not want to have to write
(Scroll down to bottom of post to find solution.) Got a asp.net page which
Is it possible to scroll down the left and right parts of a vertically
If you scroll down to the section 'Writing to Files and URLs' at this
When you scroll down to the bottom of http://www.dzone.com/links/ it automatically loads more links.
What I want to do is scroll down the window when I expand elements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.