private ListView listView=null;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
listView=(ListView)findViewById(R.id.list);
ArrayList<HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();
for(int i=0;i<5;i++)
{
HashMap<String, Object> map=new HashMap<String, Object>();
map.put("time","time"+i);
map.put("name","name"+i);
list.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list_item, new String[]{"time","name"}, new int[]{R.id.time,R.id.name});
listView.setAdapter(adapter);
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
listView=(ListView)findViewById(R.id.list);
ArrayList<HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();
for(int i=0;i<5;i++)
{
HashMap<String, Object> map=new HashMap<String, Object>();
map.put("time","time"+i);
map.put("name","name"+i);
list.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list_item, new String[]{"time","name"}, new int[]{R.id.time,R.id.name});
listView.setAdapter(adapter);
}
setListAdapter(adapter );
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/time" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textColor="#FFFFFFFF" />
<TextView android:id="@+id/name" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#FFaaaaaa"
android:textSize="14dip" />
</LinearLayout>这个Item的布局你写来吧?
<?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="fill_parent">
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name"
/>
</LinearLayout> android:text="aaaaaaaaa"
/>
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<?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="fill_parent">
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="aaaaaaaaa"
/>
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name"
/>
</LinearLayout>上面粘错了,只能显示"aaaaaaaaa"
list.xml里面layout加上这个