Android Open Source - SimpleAndroidChat Chat List Adapter

From Project

Back to project page SimpleAndroidChat.


The source code is released under:

GNU General Public License

If you think the Android project SimpleAndroidChat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.anderscore.simpleandroidchat;
//from w  ww .  java  2s  .c  om
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ChatListAdapter extends BaseAdapter {

  private Context context;
  private List<ChatMsg> messages = new ArrayList<ChatMsg>();
  static class ViewHolder {
    TextView tViewUser;
    TextView tViewMessage;
  public ChatListAdapter(Context context) {
    this.context = context;
  public int getCount() {
    return messages.size();

  public ChatMsg getItem(int position) {
    return messages.get(position);

  public long getItemId(int position) {
    return position;

  public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = convertView;
    if (rowView == null) {
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      rowView = inflater.inflate(R.layout.row_item_chat_list,parent, false);
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.tViewMessage = (TextView) rowView.findViewById(;
      viewHolder.tViewUser = (TextView) rowView.findViewById(;
    ViewHolder holder = (ViewHolder) rowView.getTag();
    ChatMsg msg = getItem(position);
    if (messages.get(position).isIncomming()) {
    else {
    return rowView;
  public void updateList(ChatMsg msg) {
  public void updateList(ArrayList<ChatMsg> messages) {
    this.messages = messages;

Java Source Code List