android - java xmlpull parse random string from XML -


i'm new android programming , i'm trying figure out how strings file , display strings on buttons randomly.

the goal make multiple choice test randomly generated questions (based on database) , keep track of user's correct , incorrect answers (but i'm far part).

i watched xmlpull tutorial showed me how pull section of every line in document , tried adapt pull section of 1 line. here's have:

string item;  @override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.test_layout);      try {         item = getitemfromxml(this);     } catch (xmlpullparserexception e) {     } catch (ioexception e) {     }      string[] items = item.split("\n");     setlistadapter (new arrayadapter<string>(this, android.r.layout.simple_list_item_1, items));  }  public string getitemfromxml(test test) throws xmlpullparserexception, ioexception {     stringbuffer stringbuffer = new stringbuffer();     resources res = test.getresources();     xmlresourceparser xpp = res.getxml(r.xml.database);     xpp.next();     int eventtype = xpp.geteventtype();     (int scount = 0; scount<1; scount++) {         if (eventtype ==xmlpullparser.start_document)         if (eventtype == xmlpullparser.start_tag) {             if (xpp.getname().equals("character")) {                 stringbuffer.append(xpp.getattributevalue(null, "english")  + "\n");             }         }         eventtype = xpp.next();     }     return stringbuffer.tostring(); } 

the xml file looks kind of this:

<root id="kanji">   <characters>     <character english="one" grade="1"/> 

how can make work pull value random line?


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -