![]()
<?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="65.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"
style="@style/MMFontTitleInList"
android:text="悠悠"
android:textSize="18sp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/img_photo"
android:layout_marginLeft="10dp"
android:singleLine="true" />
<TextView
android:id="@+id/txt_msg"
android:layout_below="@id/txt_name"
android:layout_toRightOf="@+id/img_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginLeft="12dp"
android:layout_marginTop="2dp"
android:textColor="@color/black1"
android:text="请求添加你为朋友"
android:textSize="12sp" />
<TextView
android:id="@+id/txt_add"
style="@style/txt_titleStyle1"
android:layout_width="60dp"
android:layout_height="32dp"
android:gravity="center"
android:text="接受"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textColor="@color/white"
android:background="@drawable/btn_bg_green"
android:textSize="16sp" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black2" />
</LinearLayout>
实现代码:
public class NewFriendsAdapter extends BaseAdapter {
protected Context context;
public NewFriendsAdapter(Context ctx) {
context = ctx;
}
@Override
public int getCount() {
return GloableParams.UserInfos.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.layout_item_newfriend, parent, false);
}
ImageView img_avar = ViewHolder.get(convertView, R.id.img_photo);
TextView txt_name = ViewHolder.get(convertView, R.id.txt_name);
final TextView txt_add = ViewHolder.get(convertView, R.id.txt_add);
final User user = GloableParams.UserInfos.get(position);
txt_name.setText(user.getUserName());
txt_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txt_add.setTextColor(context.getResources().getColor(R.color.black1));
txt_add.setBackgroundResource(R.drawable.btn_bg_gray1);
txt_add.setText("已添加");
Utils.showLongToast(context, "添加好友成功,等待对方同意");
try {
EMContactManager.getInstance().addContact(
user.getTelephone(), "请求添加你为朋友");
} catch (EaseMobException e) {
e.printStackTrace();
}
}
});
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, FriendMsgActivity.class);
intent.putExtra(Constants.NAME, user.getUserName());
intent.putExtra(Constants.TYPE, ChatActivity.CHATTYPE_SINGLE);
intent.putExtra(Constants.User_ID, user.getTelephone());
context.startActivity(intent);
}
});
return convertView;
}
}
点击查看好友详情。