0

MySQL DB からの選択クエリの結果として ResultSet があるので、本当に助けが必要です。テーブルレイアウトで表示するにはどうすればよいですか?? テーブルビューのレイアウトをセットアップしました

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

   }

助けてください

4

1 に答える 1

0

新しいビューを作成し (テーブルの行に TextView を入力しているようです)、必要に応じてクエリの結果を入力できます。TableRow次に、コンストラクターを使用して新しいを作成できます(ドキュメントを参照してください)。

以下を使用して、ビューをテーブル行インスタンスに追加します。

tableRowInstance.addView(viewInstance);

を同じ方法で追加しtableRowます。tableLayout

myTable.addView(tableRowInstance)

TableLayouts と TableRows はどちらも View のサブクラスです。ViewGroup、View、およびそれらがどのように構造化されているかについて調査する必要があります。このリンクは素晴らしい視覚化を提供します。

于 2013-07-15T17:34:00.523 に答える