[Android开发视频教学].01_13_Android常见控件(三)之二 学习使用ListView
list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbars="vertical" >
</ListView>
</LinearLayout>
user.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/user_ip"
android:layout_width="180dp"
android:layout_height="20dp"
android:gravity="left" />
<TextView
android:id="@+id/user_name"
android:layout_width="fill_parent"
android:gravity="right"
android:layout_height="20dp" />
</LinearLayout>
java
package fengda.android09;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class Activity09 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity09);
ArrayList<HashMap<String, String>> mapList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map1 = new HashMap<String, String>();
HashMap<String, String> map2 = new HashMap<String, String>();
HashMap<String, String> map3 = new HashMap<String, String>();
map1.put("usr_ip", "192.168.0.1");
map1.put("user_name", "一号");
map2.put("user_ip", "192.168.0.2");
map2.put("user_name", "二号");
map3.put("user_ip", "192.168.0.3");
map3.put("user_name", "三号");
mapList.add(map1);
mapList.add(map2);
mapList.add(map3);
SimpleAdapter ad = new SimpleAdapter(this, mapList, R.layout.user,
new String[] { "user_ip", "user_name" }, new int[] {
R.id.user_ip, R.id.user_name });
this.setListAdapter(ad);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}
为什么我做出来的结果是这样的?