我正在尝试从 SQLite 数据库中获取数据并在 Android 中以表格格式显示它。下面是显示数据的代码:
Cursor c=db.getAllTitles();
if(c.moveToFirst())
{
do
{
DisplayTitle(c);
}while(c.moveToNext());
}
函数如下DisplayTitle
所示:
public void DisplayTitle(Cursor c)
{
txt.setText(c.getString(0));
txt.setTextColor(Color.blue(1));
tr.addView(txt);
tl.addView(tr);
}
这里,txt
是TextView
我在类中全局声明的变量。tl
是TableLayout
变量,tr
是TableRow
我在类中全局声明的变量。
这行不通。但是,如果我使用Toast
函数,则会显示从数据库中提取的数据。请帮忙。
这是整个代码的链接: