Android Open Source - SimpleAndroidChat Chat List Adapter






From Project

Back to project page SimpleAndroidChat.

License

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;
  }
  
  @Override
  public int getCount() {
    return messages.size();
  }

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

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  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(R.id.tViewMessage);
      viewHolder.tViewUser = (TextView) rowView.findViewById(R.id.tViewUser);
      rowView.setTag(viewHolder);
    }
    ViewHolder holder = (ViewHolder) rowView.getTag();
    ChatMsg msg = getItem(position);
    holder.tViewMessage.setText(msg.getMsg());
    if (messages.get(position).isIncomming()) {
      holder.tViewUser.setText(msg.getUser());      
    }
    else {
      holder.tViewUser.setText("Ich");
    }
    return rowView;
  }
  
  public void updateList(ChatMsg msg) {
    messages.add(msg);
    notifyDataSetChanged();
  }
  
  public void updateList(ArrayList<ChatMsg> messages) {
    this.messages = messages;
    notifyDataSetChanged();
  }
  
}




Java Source Code List

com.anderscore.simpleandroidchat.AbstractActivity.java
com.anderscore.simpleandroidchat.ChatActivity.java
com.anderscore.simpleandroidchat.ChatListAdapter.java
com.anderscore.simpleandroidchat.ChatMsg.java
com.anderscore.simpleandroidchat.ConnectionAdapterEventbus.java
com.anderscore.simpleandroidchat.ConnectionAdapter.java
com.anderscore.simpleandroidchat.Constants.java
com.anderscore.simpleandroidchat.ContactListActivity.java
com.anderscore.simpleandroidchat.ContactListAdapter.java
com.anderscore.simpleandroidchat.Contact.java
com.anderscore.simpleandroidchat.DBConnection.java
com.anderscore.simpleandroidchat.DBModel.java
com.anderscore.simpleandroidchat.MessengerService.java
com.anderscore.simpleandroidchat.NotificationBuilder.java