UI的XML代码:main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/MyListView">
</ListView>
</LinearLayout>
my_listitem.xml的代码如下,my_listitem.xml用于设计ListView的Item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content"
android:id="@+id/MyListItem"
android:paddingBottom="3dip"
android:paddingLeft="10dip">
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/ItemTitle"
android:textSize="30dip">
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/ItemText">
</TextView>
<TableLayout
android:id="@+id/tl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1">
<TableRow>
<TextView
android:layout_height="wrap_content"
android:text="a1"/>
<TextView
android:layout_height="wrap_content"
android:text="a2"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/a1"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/a2"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</LinearLayout>
如果没有TableLayout的情况下是这样的循环的:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//绑定XML中的ListView,作为Item的容器
ListView list = (ListView) findViewById(R.id.MyListView);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
for(int i=0;i<30;i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("ItemTitle", "This is Titl");
map.put("ItemText", "This is text");
mylist.add(map);
}
SimpleAdapter mSchedule = new SimpleAdapter(this,
mylist,
R.layout.my_listitem,
new String[] {"ItemTitle", "ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText});
list.setAdapter(mSchedule);
}
问题:这个listview下面的TableLayout的数据我是从数据库取出来循环显示的,那么我怎么写呢?