Android Open Source - SimpleAndroidChat Contact 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 .ja  va 2  s  . co  m
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 ContactListAdapter extends BaseAdapter {
  List<Contact> contacts = new ArrayList<Contact>();
  Context context;
  public ContactListAdapter(Context context) {
    this.context = context;
  public int getCount() {
    return contacts.size();
  public Contact getItem(int position) {
    return contacts.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_contact_list, parent, false);
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.tViewUser = (TextView) rowView.findViewById(;
    ViewHolder holder = (ViewHolder) rowView.getTag();    
    if (contacts.get(position).isOnline()) {
      holder.tViewUser.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.circle_green, 0);
    } else {
      holder.tViewUser.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.circle_gray, 0);
    return rowView;
  public void updateList(ArrayList<Contact> contacts) {
    this.contacts = contacts;
  private static class ViewHolder {
    public TextView tViewUser;

Java Source Code List