本案例使用自定义布局实现在ListView中显示数据库的数据(用户名、手机号)的功能,ListView向上滑动可以加载更多数据。
1.user_item.xml
<?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:orientation="horizontal" >
<TextView
android:id="@+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="chj" />
<TextView
android:id="@+id/tv_phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="13527168697" />
<Button
android:id="@+id/btn_call"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="拨号" />
<Button
android:id="@+id/btn_sms"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="信息" />
</LinearLayout>
2.在activity_main.xml中添加ListView控件 id=”@+id/lv_users”
3.自定义的adapter UserAdapter.java
package com.example.dbhytc.adapter;
import java.util.List;
import java.util.Map;
import android.content