Android 用数据数组填充表

Android 用数据数组填充表,android,listview,android-tablelayout,populate,Android,Listview,Android Tablelayout,Populate,我想设置一个表,它有固定数量的列,和X数量的行,第一行列出每列的内容。例如,一列将是“Name”,第二列将是“Age”,然后将有X个存储数据的行。是否有任何方法可以在其他地方为该数据设置数组,并自动使用该数据创建/填充表中的行。我以前用一个更简单的例子使用自定义适配器完成了这项工作,但我不太确定如何在涉及表的情况下完成这项工作。我被卡住了,任何帮助都将不胜感激。我认为在表格布局中创建tablerow如下所示 <TableLayout --- > <TableRow -- >

我想设置一个表,它有固定数量的列,和X数量的行,第一行列出每列的内容。例如,一列将是“Name”,第二列将是“Age”,然后将有X个存储数据的行。是否有任何方法可以在其他地方为该数据设置数组,并自动使用该数据创建/填充表中的行。我以前用一个更简单的例子使用自定义适配器完成了这项工作,但我不太确定如何在涉及表的情况下完成这项工作。我被卡住了,任何帮助都将不胜感激。

我认为在表格布局中创建tablerow如下所示

<TableLayout
---
>
<TableRow
--
>
<Textview
for name
/>
<Textview
...for age
/>

</TableRow>
<TableRow
--
>
<Listview
for name
/>
<Listview
...for age
/>

</TableRow>

</TableLayout>

ListView
基本上充当任何数据表中的一行。您应该创建一个POJO,其中包含要在一行中显示的所有属性。您可以为数据创建自定义xml布局,该布局可能通过与列对应的水平
LinearLayout

波乔

ListView项目布局(layout\u list\u item.xml)


主布局

<?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"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="0dip"
                android:layout_weight="0.7"
                android:text="Name" />

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="0dip"
                android:layout_weight="0.3"
                android:text="Age" />

        </LinearLayout>

        <ListView
            android:id="+@id/MyDataListView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

     </LinearLayout>


然后,您需要一个自定义适配器,该适配器使用POJO中的值设置列表视图中的字段。互联网上有很多这方面的教程。

谢谢你的帮助,但我已经做到了。我想知道的是如何使用链接到对象数组的某种适配器自动填充每行中的数据。非常感谢您的帮助!谢谢你!您是否有机会获得您认可的上述教程的链接?谢谢
public class MyData {
    public String Name;
    public int Age;
    // More data here
}
<?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="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/Name"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="0.7" />

        <TextView
            android:id="@+id/Age"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="0.3" />

    </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"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="0dip"
                android:layout_weight="0.7"
                android:text="Name" />

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="0dip"
                android:layout_weight="0.3"
                android:text="Age" />

        </LinearLayout>

        <ListView
            android:id="+@id/MyDataListView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

     </LinearLayout>