I am trying to get the data from SQLite database and display it in a table format in Android. Here is the code for displaying data:
Cursor c=db.getAllTitles();
if(c.moveToFirst())
{
do
{
DisplayTitle(c);
}while(c.moveToNext());
}
And the DisplayTitle function looks as shown below:
public void DisplayTitle(Cursor c)
{
txt.setText(c.getString(0));
txt.setTextColor(Color.blue(1));
tr.addView(txt);
tl.addView(tr);
}
Here, txt is a TextView variable that I have globally declared in the class. tl is the TableLayout variable and tr is TableRow variable that I have declared globally in the class.
This doesn't work. However, if I use Toast function, the data pulled from the database is getting displayed. Please help.
Here is the link to the entire code: