46、微信-群聊列表

仍然使用通用布局 activity_listview,不过添加了一个列表头:
View layout_head = getLayoutInflater().inflate(R.layout.layout_head_search, null);
mlistview.addHeaderView(layout_head);
用于搜索。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txt_search"
android:layout_width="fill_parent"
android:layout_height="33dp"
android:drawableLeft="@drawable/search_icon"
android:background="@drawable/search_ba"
android:layout_margin="15dp"
android:paddingLeft="20dp"
android:text="@string/search"
android:drawablePadding="10dp"
android:textColor="@color/black1"
android:gravity="center|left"
android:singleLine="true" />

</LinearLayout>
通过服务器获取群聊列表:
@Override
protected void initView() {
try {
List<EMGroup> grouplist = EMGroupManager.getInstance().getGroupsFromServer();
if (grouplist != null && grouplist.size() > 0) {
mlistview.setAdapter(new MyGroupAdpter(this, grouplist));
} else {
TextView txt_nodata = (TextView) findViewById(R.id.txt_nochat);
txt_nodata.setText("暂时没有群聊");
txt_nodata.setVisibility(View.VISIBLE);
}
} catch (EaseMobException e) {
e.printStackTrace();
}
}
群聊适配器:
public class MyGroupAdpter extends BaseAdapter {
protected Context context;
private List<EMGroup> grouplist;

public MyGroupAdpter(Context ctx, List<EMGroup> grouplist) {
context = ctx;
this.grouplist = grouplist;
}

@Override
public int getCount() {
return grouplist.size();
}

@Override
public Object getItem(int position) {
return null;
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.layout_item_mygroup, parent, false);
}
final EMGroup group = grouplist.get(position);
ImageView img_avar = ViewHolder.get(convertView, R.id.img_photo);
TextView txt_name = ViewHolder.get(convertView, R.id.txt_name);
img_avar.setImageResource(R.drawable.defult_group);
txt_name.setText(group.getGroupName());
convertView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(context, ChatActivity.class);
intent.putExtra(Constants.NAME, group.getGroupName());
intent.putExtra(Constants.TYPE, ChatActivity.CHATTYPE_GROUP);
intent.putExtra(Constants.GROUP_ID, group.getGroupId());
context.startActivity(intent);
}
});
return convertView;
}
}
子项布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60.0dip"
android:background="@drawable/setting_item_selector"
android:paddingLeft="10dip">
<ImageView
android:id="@+id/img_photo"
android:layout_width="45dip"
android:layout_height="45dip"
android:layout_centerVertical="true"
android:src="@drawable/head" />
<TextView
android:id="@+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="车友群"
android:textSize="18sp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/img_photo"
android:layout_marginLeft="13dp"
android:singleLine="true" />

</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black2" />

</LinearLayout>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

asmcvc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值