java - first questions and answers is repeating when i set into the textview? -


i have lot of questions , answers in mysql database , creating quiz app when set them up, getting questions , answer through mysql database using json first question , answers it. how can set questions , answers how can using loop in code please help?

    json_string=getintent().getextras().getstring("j");     try {         jsonobject=new jsonobject(json_string);         jsonarray=jsonobject.getjsonarray("server_response");         if(jsonarray.length()!=0){             jsonobject jo=jsonarray.getjsonobject(count);             ques = jo.getstring("questiontext");             options=jo.getstring("options").split("##");             ans = integer.parseint(jo.getstring("correctanswer"));          }     } catch (jsonexception e) {         e.printstacktrace();     }      if (savedinstancestate == null) {         bundle extras = getintent().getextras();         if (extras == null) {          } else {              answers=extras.getstring("uranswers");         }     }     l=(linearlayout)findviewbyid(r.id.review);     scrollview scrollview= new scrollview(this);     linearlayout lin =new linearlayout(this);     int i;     (i=0;i<jsonarray.length();i++){         textview qus = new textview(this);         qus.settextsize(20);         qus.settextcolor(color.white);         qus.setpadding(0, 20, 0, 0);         qus.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, linearlayout.layoutparams.wrap_content));         textview opta = new textview(this);         textview optb = new textview(this);         textview optc = new textview(this);         textview optd = new textview(this);         textview urans = new textview(this);         textview correctans = new textview(this);         qus.settext (" question. no.(" + (questionno + 1) + ").\n " + ques);         opta.settext("(a). " + options[0].tostring() + "\n");         optb.settext("(b). " + options[1].tostring() + "\n");         optc.settext("(c). " + options[2].tostring() + "\n");         optd.settext("(d). " + options[3].tostring() + "\n\n");          string = "";         int color = 0;         string answers1 = answers.substring(i, + 1);         string correct = string.valueof(ans);         if (answers1.equals("5")) {             = "unanswered";             color = color.yellow;         }         if (answers1.equals("1")) {             = "a";             if (correct.equals("1"))                 color = color.green;             else                 color = color.red;         }         if (answers1.equals("2")) {             = "b";             if (correct.equals("2"))                 color = color.green;             else                 color = color.red;         }         if (answers1.equals("3")) {             = "c";             if (correct.equals("3"))                 color = color.green;             else                 color = color.red;         }         if (answers1.equals("4")) {             = "d";             if (correct.equals("4"))                 color = color.green;             else                 color = color.red;         } else {         }          string b = "";           if (correct.equals("1")) {             b = "a";         }         if (correct.equals("2")) {             b = "b";         }         if (correct.equals("3")) {             b = "c";         }         if (correct.equals("4")) {             b = "d";         } else {          }          urans.settext("your answer :" + a.tostring() + "\n");         urans.settextsize(18);         urans.settextcolor(color);         correctans.settext("correct answer :" + b.tostring() + "\n\n");         correctans.settextsize(18);         correctans.settextcolor(color.green);         lin.addview(qus);         lin.addview(opta);         lin.addview(optb);         lin.addview(optc);         lin.addview(optd);         lin.addview(urans);         lin.addview(correctans);         opta.settextsize(18);         //opta.setpadding(0,30,0,0);         opta.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, linearlayout.layoutparams                 .wrap_content));         opta.settextcolor(color.white);         optb.settextsize(18);         optb.settextcolor(color.white);         //opta.setpadding(0,30,0,0);         optb.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, linearlayout.layoutparams                 .wrap_content));         optc.settextsize(18);         opta.setpadding(0, 30, 0, 0);         optc.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, linearlayout.layoutparams                 .wrap_content));         optc.settextcolor(color.white);         optd.settextsize(18);         //opta.setpadding(0,30,0,0);         optd.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, linearlayout.layoutparams                 .wrap_content));         optd.settextcolor(color.white);     }      scrollview.addview(lin);     scrollview.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.fill_parent,             linearlayout.layoutparams.fill_parent));     scrollview.setpadding(20,10,10,20);     lin.setorientation(linearlayout.vertical);     getwindow().setbackgrounddrawableresource(r.drawable.back3);     setcontentview(scrollview); }  } 

first of learn how use recyclerview here link recyclerview tutorial , learn how parse json json parsing tutorial learning these 2 tutorial sure problem in future.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -