实现基于OPhone 2.0的GTalk客户端
2010-10-19 20:56:29 来源:WEB开发网contact.account = entry.getUser();
// 设置联系人的昵称
contact.nickname = mUtil.getLeftString(entry.getUser(), "@");
mContacts.add(contact);
mContactMap.put(contact.account, mContacts.size() - 1);
}
}
@Override
public int getCount()
{
return mContacts.size();
}
@Override
public Object getItem(int position)
{
return mContacts.get(position);
}
public String getAccount(int position)
{
return mContacts.get(position).account;
}
@Override
public long getItemId(int position)
{
return position;
}
// 设置联系人的图标资源ID。当联系人上线或离线时需要调用该方法来改变联系人前面的图标
public void setContactIcon(String account, int resourceId)
{
Integer position = mContactMap.get(account);
if (position != null)
{
// 如果联系人图标资源ID已变化,则设置新的图标资源ID
if (mContacts.get(position).iconResourceId != resourceId)
{
mContacts.get(position).iconResourceId = resourceId;
notifyDataSetChanged();
}
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout linearLayout = (LinearLayout) mLayoutInflater.inflate(R.layout.contact_item, null);
ImageView ivContactIcon = (ImageView) linearLayout.findViewById(R.id.ivContactIcon);
TextView tvContactNickname = ((TextView) linearLayout.findViewById(R.id.tvContactNickname));
// 设置联系人图标资源ID
ivContactIcon.setImageResource(mContacts.get(position).iconResourceId);
// 设置联系人昵称
tvContactNickname.setText(mContacts.get(position).nickname);
更多精彩
赞助商链接