【问题标题】:Android : Loading table data at run timeAndroid:在运行时加载表数据
【发布时间】: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


【解决方案1】:

你需要做一些阅读

ListView

Custom ListView Adapter

基本思路:

1)你已经有了布局xml,让它与listview兼容[那是你不需要表格布局]

2) 制作一个 ListView 并为其编写自定义适配器类

3) 您可以选择将 XML 布局作为 ListViewItem 膨胀到 ListView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 2013-10-25
    • 2017-10-21
    • 1970-01-01
    相关资源
    最近更新 更多