gpt4 book ai didi

android - 在 TableView 中显示结果集

转载 作者:行者123 更新时间:2023-11-30 01:29:14 26 4
gpt4 key购买 nike

我真的需要帮助我有一个 ResultSet 作为来自 MySQL DB 的选择查询的结果。如何在表格布局中显示它?我已经设置了表格 View 的布局

<?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">

<EditText
android:id="@+id/myFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/some_hint" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:padding="10dp"
android:text="@string/some_text" android:textSize="20sp" />
<TableLayout
android:id="@+id/producttablelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerPadding="@dimen/activity_horizontal_margin"
android:scrollbars="horizontal|vertical"
android:showDividers="none|beginning|middle|end" >

<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|bottom|left|right"
android:paddingTop="@dimen/activity_horizontal_margin" >

<TextView
android:id="@+id/ttt1"
android:text="Column 1"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/ttt2"
android:text="Column 12"
android:textAppearance="?android:attr/textAppearanceLarge" />


</TableRow>

</TableLayout>

</LinearLayout>

我希望能够将 ResultSet 数据添加到其中。像这样的东西:

    super.onCreate(savedInstanceState);
String s = null;
setContentView(R.layout.activity_list_all_products);
// Show the Up button in the action bar.
setupActionBar();
context333=this;
TableLayout myTable = (TableLayout)findViewById(R.id.producttablelayout);
try
{
connect2 = DriverManager.getConnection(LogonActivity.url, LogonActivity.user, LogonActivity.password);
statement2 = connect2.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
preparedStatement2 = connect2.prepareStatement("select article_code,article_desc from products limit 4");
resultSet2=preparedStatement2.executeQuery();
resultSet2.beforeFirst();

while (resultSet2.next()) {
how to add next record here to the table layout??

}

请帮忙

最佳答案

您可以创建一个新的 View (看起来您正在使用 TextView 填充表行)并根据需要使用查询结果填充它们。然后,您可以使用构造函数 (see the documentation) 创建一个新的 TableRow

使用以下方法将 View 添加到表行实例:

tableRowInstance.addView(viewInstance);

然后以同样的方式将tableRow添加到tableLayout:

myTable.addView(tableRowInstance)

TableLayouts 和 TableRows 都是 View 的子类。您应该对 ViewGroup、View 以及它们的结构进行一些研究。 This link提供了很好的可视化效果。

关于android - 在 TableView 中显示结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17659366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com