0

我正在尝试在 android 程序中以表格形式显示表格数据。

我的桌子:

orderno   productid   productqty   custid
1         1000001      2            00010
2         1000001      5            00010

我想在 android 前端显示该表。为此,我编写了以下程序:

 dbadapter.open();
 Cursor cursor=dbadapter.fetchordersdata(custid);
 int count=cursor.getCount();

从这里我得到表格数据。如何以表格形式排列这些数据?

4

2 回答 2

3

从数据库中获取数据并将数据附加到字符串并将此 str 加载到 Web 视图遵循此代码

String mStr="";

mStr=mStr.concat("<body >");
mStr=mStr.concat("<tr><td align='center'><b>orderno</b></td><td align='center'><b>productid</b></td><td align='center'><b>productqty</b></td>
<td align='center'><b>custid</b></td></tr>");

dbadapter.open();
Cursor cursor=dbadapter.fetchordersdata(custid);
cursor.moveToFirst();
while(!cursor.isAfterLast())
            {
mStr=mStr.concat("<tr><td>"+(cursor.getString(cursor.getColumnIndex("col1")))+"</td><td>"+(cursor.getString(cursor.getColumnIndex("col2")))+"</td>
<td>"+(cursor.getString(cursor.getColumnIndex("col3")))+"</td>
<td>"+(cursor.getString(cursor.getColumnIndex("col4")))+"</td></tr>");


  cursor.moveToNext();
}

   mStr.concat("</table></body>");

我希望这段代码能帮助你... WebView web =(WebView)findViewById(R.id.webview); web.loadData(mStr,"text/html",null);

于 2012-11-15T11:06:39.527 回答
0

在 XML 方面:创建一个表视图。

在 src 方面:创建一个对象(称为数据访问对象),负责连接数据库、检索您需要的数据并将该信息放入表视图中。

于 2012-11-15T10:01:59.823 回答