android - Replacing json retrieval with database retrieval in project -


apologies if i'm not providing enough information here, i'm new android/java , learning combining elements of various example projects.

i have working verticalgridfragment page android tv project (using leanback) loads album cover art , details in columns , rows. borrows heavily googlesamples example on github.

using test music_database_proto.json file in format of:

{   "cards": [     {       "type": "grid_square",       "title": "around world in day",       "artist": "prince , revolution",       "description": "prince , revolution",       "grouptype": 0,       "tagid": 0,       "localimageresource": "food_01"     } } 

i can load using createrows() function (from same sample project) using:

presenterselector cardpresenterselector = new cardpresenterselector(getactivity()); madapter = new arrayobjectadapter(cardpresenterselector); string json = utils.inputstreamtostring(getresources().     openrawresource(r.raw.music_database_proto)); cardrow row = new gson().fromjson(json, cardrow.class); madapter.addall(0, row.getcards()); 

which uses sample projects classes of cardrow.class, card.class , various supporting classes in example.

i've implemented sqlite database initiates , can call various results in logs of android studio. don't know start inserting results database cards can load verticalgridfragment, replacing function of json file?

i thought simple creating list<card> database results , adding madapter using madapter.addall. however, i've had little luck in implementing list of card objects using iterating code. desperately, thought should turn database results json string , feed them existing code showed above?

any appreciated. database basic recreation of json variables , can adjusted suit.

what mean however, i've had little luck in implementing list of card objects using iterating code.? if you're calling madapter.addall(0, cards) list of cards, should work desire.

are having difficulty extracting list of cards sqlite database? can rely on this link has following answer. i've modified card.class. you'll need add constructor card object since provided assuming you'd use @serializedname initialize it. below example assumes you've added constructor looks public card(string title, string description).

list<card> cardslist = new arraylist<card>(); database = openorcreatedatabase("your_db", sqlitedatabase.open_readwrite, null); if(database!=null) {     c= database.rawquery(query, null);     c.movetofirst();     while(c.isafterlast()==false)     {         card card = new card(c.getstring(c.getcolumnindex("title")),                              c.getstring(c.getcolumnindex("description")));         cardslist.add(card);         c.movetonext();     }  } database.close(); c.close(); 

the example starting point, encourage customize of classes within sample better fit needs.

i you're trying learn sqlite since it's piece of android (and mobile development in general) familiar with. can use library stetho facebook make sure sqlite tables contain correct data. makes debugging little easier.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -