本人写了个ListView的测试程序,但最终结果显示不出来,用logcat提示:
04-04 07:14:26.308: INFO/AndroidRuntime(337): NOTE: attach of thread 'Binder Thread #3' failed
04-04 07:14:28.218: INFO/ActivityManager(60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=gao.ListView/.ListViewTest }
04-04 07:14:28.278: INFO/AndroidRuntime(345): NOTE: attach of thread 'Binder Thread #3' failed
我写的代码如下:
ListViewTest.java代码:
(1)package gao.ListView;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class ListViewTest extends ListActivity {
public void onCreate(Bundle savedInstanceState, String gao) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList< HashMap<String,String>> list = 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("user_name", "gao");
map1.put("user_ip","192.168.0.1");
map2.put("user_name", "yang");
map2.put("user_ip", "192.168.0.2");
map3.put("user_name","li");
map3.put("uaer-ip","192.168.0.3");
list.add(map1);
list.add(map2);
list.add(map3);
SimpleAdapter listAdapter=new SimpleAdapter(this, list, R.layout.user,
new String[]{"user_name","user_ip"},
new int[]{R.id.user_name,R.id.user_ip});
setListAdapter(listAdapter);
}
}
(2)main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
></ListView>
</LinearLayout>
(3)user.xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt"
android:singleLine="true"
></TextView>
<TextView
android:id="@+id/user_ip"
android:layout_width="wrap_content"