So I'm working in Android studio, with Java as my language, and I've got an embedded database. I'd like to press some button on my app to display everything that's in my database at that point in time. Let's assume my database carries letter-number combinations, eg "A,45", "B,57" etc
Now to display this data in my app I'm using the following method:
LinearLayout my_layout = (LinearLayout)findViewById(R.id.mainView);
Cursor c = dbase.query("SELECT letter, number from database");
while (c.moveToNext()){
TextView t = new TextView(this);
t.setText(c.getString(c.getColumnIndex("letter"))+","+c.getLong(c.getColumnIndex("number")));
my_layout.addView(t);
}
c.close();
Now this works fine to display my data the first time I press the button on my app, but the problem is on subsequent presses the already displayed data remains on screen, and eventually the screen runs out of space.
Eg, press once:
A,45
B,57
press again:
A,45
B,57
A,45
B,57
and so on.
How can I modify my loop so that on each new press the current contents of the screen are erased? Any help appreciated.