41、微信-添加新朋友NewFriendsListActivity

来源:互联网 发布:人工智能电影排名 编辑:程序博客网 时间:2024/04/29 12:11
使用的是通用的activity_listview布局,但是增加了一个列表头:
layout_head = getLayoutInflater().inflate(R.layout.layout_head_newfriend, null);
mlistview.addHeaderView(layout_head);
mlistview.setAdapter(new NewFriendsAdapter(this));

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

<include layout="@layout/layout_head_search"/>
<View
android:background="@color/black2"
android:layout_width="fill_parent"
android:layout_height="1.0dip" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/white">

<TextView
android:id="@+id/txt_tel"
android:layout_weight="1"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:drawableTop="@drawable/a6_"
android:text="添加手机联系人"
android:textColor="#9A9A9A"
android:textSize="14sp" />
<View
android:background="@color/black2"
android:layout_width="1.0dip"
android:layout_height="fill_parent" />
<TextView
android:id="@+id/txt_qq"
android:layout_weight="1"
android:gravity="center"
android:drawableTop="@drawable/a6a"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:text="添加QQ好友"
android:textColor="#9A9A9A"
android:textSize="14sp" />
</LinearLayout>

<View
android:background="@color/black2"
android:layout_width="fill_parent"
android:layout_height="1.0dip" />
<TextView
android:layout_width="match_parent"
android:layout_height="36dp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:text="新的朋友"
android:textSize="12sp" />
</LinearLayout>
看实现代码:
public class NewFriendsListActivity extends BaseActivity implements
View.OnClickListener {
private TextView txt_title, txt_right;
private ImageView img_back;
private ListView mlistview;
private View layout_head;

@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_listview);
super.onCreate(savedInstanceState);
}

@Override
protected void initControl() {
txt_title = (TextView) findViewById(R.id.txt_title);
txt_title.setText("新的朋友");
txt_right = (TextView) findViewById(R.id.txt_right);
txt_right.setText("添加朋友");
img_back = (ImageView) findViewById(R.id.img_back);
img_back.setVisibility(View.VISIBLE);
mlistview = (ListView) findViewById(R.id.listview);
layout_head = getLayoutInflater().inflate(R.layout.layout_head_newfriend, null);
mlistview.addHeaderView(layout_head);
mlistview.setAdapter(new NewFriendsAdapter(this));
}

@Override
protected void initView() {

}

@Override
protected void initData() {
}

@Override
protected void setListener() {
img_back.setOnClickListener(this);
txt_right.setOnClickListener(this);
layout_head.findViewById(R.id.txt_search).setOnClickListener(this);
layout_head.findViewById(R.id.txt_tel).setOnClickListener(this);
layout_head.findViewById(R.id.txt_qq).setOnClickListener(this);

}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.img_back:
Utils.finish(NewFriendsListActivity.this);
break;
case R.id.txt_right:
Utils.start_Activity(this, PublicActivity.class, new BasicNameValuePair(Constants.NAME, "添加朋友"));
break;
case R.id.txt_search:
Utils.start_Activity(this, PublicActivity.class, new BasicNameValuePair(Constants.NAME, "搜索"));
break;
case R.id.txt_tel:
Utils.start_Activity(this, AddFromContactActivity.class);
break;
case R.id.txt_qq:
Utils.start_Activity(this, PublicActivity.class, new BasicNameValuePair(Constants.NAME, "添加QQ好友"));
break;
default:
break;
}
}
}



0 0
原创粉丝点击