Storing and Retrieving Image Path From android application folder On Pre Created SQLite Database & Setting the image to Image View -


i'm trying make simple application quiz, have image attached each question 4 answers, have 100++ images store in database

so far can figure out how make questions without image on each question trough tutorial here : chuck application part 1

i've found out way store image path hardcoding path textfields in sqlite database links below

saving resources path in sqlite

according link above, stated saves reference of image typing "r.drawable.picture1" text field inside sqlite database,

if it's true, correct way (by saving image in drawable folders , writing path text field)? if it's not what's correct way so,

how construct image path (setting setter , getter methods) getting field database?,

and how set path imageview?

any appreciated, thankyou in advance

update

so learned link how use string reference , edited string below, imagei.getimage1(); refers row database contains image name

private void showimage() {         string imagea = imagei.getimage1();         int imageresource = getresources().getidentifier(imagea , "drawable", context.getpackagename());         imageview gambar = (imageview) findviewbyid(r.id.imagetest);          drawable image = getresources().getdrawable(imageresource);          gambar.setimagedrawable(image);     } 

but got force close, did wrong?
far i've tried writing in database row

r.drawable.picture drawable/picture picture 

but nothing works....

this query

    public list<imagequestions> getimagequestionset(int ingroup, int numq) {         list<imagequestions> questionset = new arraylist<imagequestions>();         cursor c = mydatabase.rawquery("select * imagetest ingroup=" + ingroup +                 " order random() limit " + numq, null);          while (c.movetonext()){                       //log.d("imagequestions", "images found in db: " + c.getstring(1));                imagequestions = new imagequestions();                i.setquestion(c.getstring(1));                i.setimage1(c.getstring(2));                i.setanswer(c.getstring(3));                i.setoption1(c.getstring(4));                i.setoption2(c.getstring(5));                i.setgroup(ingroup);                questionset.add(i);            }                     return questionset;         } } 

this log cat

07-18 03:28:41.283: w/dalvikvm(647): threadid=1: thread exiting uncaught exception (group=0x4001d800) 07-18 03:28:41.293: e/androidruntime(647): fatal exception: main 07-18 03:28:41.293: e/androidruntime(647): caused by: java.lang.indexoutofboundsexception: invalid index 0, size 0 07-18 03:28:41.293: e/androidruntime(647):  @ java.util.arraylist.throwindexoutofboundsexception(arraylist.java:257) 07-18 03:28:41.293: e/androidruntime(647):  @ java.util.arraylist.get(arraylist.java:311) 07-18 03:28:41.293: e/androidruntime(647):  @ learning.everything.quiz.gameplayi.getnextquestion(gameplayi.java:113) 07-18 03:28:41.293: e/androidruntime(647):  @ learning.everything.bigass.oncreate(bigass.java:32) 07-18 03:28:41.293: e/androidruntime(647):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 07-18 03:28:41.293: e/androidruntime(647):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2627)   

i realized caused getting arraylist database here gameplayi class

    public class gameplayi {      private list<imagequestions> questions = new arraylist<imagequestions>();         public void setquestions(list<imagequestions> questions) {         this.questions = questions;         }       public void addquestions(imagequestions i) {         this.questions.add(i);     }       public list<imagequestions> getquestions() {         return questions;     }       public imagequestions getnextquestion() {          //get question          //below line 113\\         imagequestions next = questions.get(this.getround());         //update round number next round         this.setround(this.getround()+1);         return next;      }  }      public void setnumrounds(int numrounds) {     this.numrounds = numrounds;         }      public int getnumrounds() {     return numrounds; } 

i save image name in db , resource identifier context.getresources().getidentifier(). check out this similar question.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -