制作内容数据库列表

时间:2010-12-21 20:59:20

标签: android sqlite

如何让android中的内容数据库以列表形式查看?这是我的代码:

public void showData() {

    try {
        txt_diary.append("\n");
        String[] field = { "recID", "date", "isi" };
        Cursor c = myDb.query("diary", field, null, null, null, null,
                "recID");
        int theTotal = c.getCount();
        Toast.makeText(getApplicationContext(), "Total diary :" + theTotal,
                1).show();

        int fieldID = c.getColumnIndex("recID");
        int fieldDATE = c.getColumnIndex("date");
        int fieldISI = c.getColumnIndex("isi");
        while (c.moveToNext()) {
            field[0] = Integer.toString((c.getInt(fieldID)));
            field[1] = c.getString(fieldDATE);
            field[2] = c.getString(fieldISI);



            txt_diary.append(field[0] + " " + field[1] + " " + field[2]
                    + "\n");

        }

    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), e.getMessage(),
                Toast.LENGTH_SHORT).show();
    }

}

1 个答案:

答案 0 :(得分:0)