How to create listview for displaying sender receiver messages using baseadapter?
<p>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..</p>

<p>public class NewReadMessageAdapter extends BaseAdapter {
    private Context context;</p>

<pre><code>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&lt;Messages&gt; messages = new ArrayList&lt;Messages&gt;();

private TextView txt_msg;

private TextView txt_name;

private TextView txt_time;
Button btn_loc;
private ImageView img;

 private ArrayList&lt;Messages&gt; mData = new ArrayList&lt;Messages&gt;();
 private TreeSet&lt;Integer&gt; mSeparatorsSet = new TreeSet&lt;Integer&gt;();
 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 &lt; 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 &lt; 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;
}
</code></pre>

<p>}</p>
