3

I have a database class which stores a database and access to all of the records via the following:

public Cursor getAllRecords() {
        return db.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TEXT}, null, null, null, null, null);
    }

How can I update the TableLayout to show the field KEY_TEXT entries in it?

And furthermore, is it possible (keeping in mind that I do have both methods for deletion and insertion) to implement a way to tap a entry in the table and have it deleted (and have entries added) viewing it happen in real time, i.e.: When I tap something to delete it it should disappear from the table view too.

Tim
  • 1,056
  • 4
  • 17
  • 34

2 Answers2

0

There is no way to accomplish filling out a tablelayout the way you want, without just manually doing it with a loop of populating each row in your table layout with data from each cursor iteration.

I'm guessing what you want is some kind of way to do it with an adapter, in which case what I would advise is taking a look at this: https://stackoverflow.com/a/7971202/1359772

You will want to use a multicolumn list view with each row corresponding to a row in the query result. This way you can use list adapters to avoid having to do each entry manually. Then, you can easily set an list onitemselected listener to delete your list entry and the corresponding value from the database.

Edit

To clarify, what i'm saying is you would be better served doing this as a listview, where each item in the listview just has sections that will simulate your columns. Draw a vertical line using a stroke in the item layout if you want further separation in terms of clearly defined columns.

Community
  • 1
  • 1
D Yao.
  • 391
  • 1
  • 6
  • I probably worded the question wrong - I don't mind using either Layout as long as it gets the job done. In which case... How would you do this with a ListView? :) Please help! – Tim Aug 23 '12 at 18:10
  • It would be quite a bit simpler...have you used a listview before? You should look up some tutorials on using a CursorAdapter. It's a well-suited adapter for getting a listview to tie into a cursor. I believe it should be exactly what you're looking for... http://blog.cluepusher.dk/2009/11/16/creating-a-custom-cursoradapter-for-android/ is one, but maybe you can find more. Cheers – D Yao. Aug 23 '12 at 18:24
0

YOu should use a listview and cursor adapter. THen bind the cursor adapter to the array or list that you get from that query

Shaun
  • 5,483
  • 10
  • 40
  • 49