Note that there are some explanatory texts on larger screens.

plurals
  1. POPagination in Android
    text
    copied!<p>I am</p> <ul> <li>writing an app to attend a quiz. </li> <li>obtaining the questions from a json. </li> <li>able to populate the questions along with the options using a custom adapter extending BaseAdapter.</li> </ul> <p><strong>Problem</strong></p> <p>As the list goes bigger, it is difficult to answer. What I want is each question to be displayed in one layout. When the user clicks on next it should load the next question.</p> <p>QuizView.java</p> <pre><code>List&lt;Quiz&gt; quizList = new ArrayList&lt;Quiz&gt;(); String json = "[{\"question\": \"What?\", \"option1\": \"alpha\" , \"option2\": \"beta\" , \"option3\": \"gamma\" , \"option4\": \"alpha\"},{\"question\": \"What?\", \"option1\": \"alpha\" , \"option2\": \"beta\" , \"option3\": \"gamma\" , \"option4\": \"alpha\"}]"; Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray array = parser.parse(json).getAsJsonArray(); for(JsonElement obj : array) { Quiz quiz = gson.fromJson(obj,Quiz.class); String question = quiz.getQuestion(); System.out.println("Question: "+question); quizList.add(quiz); </code></pre> <p>Quiz.java</p> <pre><code>public class Quiz { public String question; public String option1; public String option2; public String option3; public String option4; public void setQuestion(String question) { this.question = question; } public String getQuestion() { return question; } public void setOption1(String option1) { this.option1 = option1; } public String getOption1() { return option1; } public void setOption2(String option2) { this.option2 = option2; } public String getOption2() { return option2; } public void setOption3(String option3) { this.option3 = option3; } public String getOption3() { return option3; } public void setOption4(String option4) { this.option4 = option4; } public String getOption4() { return option4; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload