【发布时间】:2013-10-25 10:16:55
【问题描述】:
在我的 android 应用程序中,我需要在运行时加载 TableLayout。我已经实现了一种从返回ArrayList 的 SQLite 数据库中检索数据的方法。我想要做的是如何在运行时将这些检索到的数据加载到TableLayout 中?我需要为它编写一个单独的方法。在我的 xml 文件中,我已经定义了一个 TableLayout,如下所示。我需要在这个TableLayout 中加载表数据。如果有人能如此友好地解释我该怎么做,我将不胜感激?
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbarSize="5dp"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/tblPersons"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
提前感谢
【问题讨论】:
-
虽然这当然是可能的,但请考虑使用 ListView 来显示数据列表。 ListViews 就是为这种事情而设计的。
-
foreach elem in array {inflate tablerow; set tablerow fields with data from elem; tblPersons.addView(tablerow); }但正如 Ken 所写,ListView 是更好的选择
标签: java android android-tablelayout