Android Open Source - SimpleAndroidChat Contact 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 .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;
  }
  @Override
  public int getCount() {
    return contacts.size();
  }
  @Override
  public Contact getItem(int position) {
    return contacts.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_contact_list, parent, false);
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.tViewUser = (TextView) rowView.findViewById(R.id.tViewUser);
      rowView.setTag(viewHolder);
    }
    ViewHolder holder = (ViewHolder) rowView.getTag();    
    holder.tViewUser.setText(contacts.get(position).getUser());
    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;
    notifyDataSetChanged();
  }
  private static class ViewHolder {
    public TextView tViewUser;
  }
}




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