有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在安卓中以表格形式排列sqllite表数据?

我试图在安卓程序中以表格形式显示表格数据

我的桌子:

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

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

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

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


共 (2) 个答案

  1. # 1 楼答案

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

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

  2. # 2 楼答案

    从数据库中获取数据,并将数据附加到字符串中,然后将这个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)findviewbyd(R.id.WebView); 网状物加载数据(mStr,“文本/html”,空)