Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:14:23+00:00 2026-06-02T06:14:23+00:00

So I’m making a quiz for android and I have a problem. I parse

  • 0

So I’m making a quiz for android and I have a problem. I parse the questions and answers from a server in JSONArrays and get what I want. So when I start the activity the first question with its associated answers are displayed, the question in a TextView and the answers in a ListView. But here’s the problem, I want to see the next question when I select an answer, so I want to loop through the JSONObject and display a new question when the previous has been answered. Anyone have any idea how I can do that?

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.game);
    listView = (ListView)findViewById(R.id.list_answers);
    gametv = (TextView)findViewById(R.id.text_question);

    Intent intent = getIntent();

    final String gameID = intent.getStringExtra("gameID");
    final int questionAmount = intent.getIntExtra("amount", 0);
    final Set<String> set = new HashSet<String>();


    JSONArray quiz = null;
    try {
        JSONObject json = new JSONObject();
        json.put("gameID", gameID);

        quiz = SendHttp.parseHttp(qURL, "result", json);



            displayQuiz(quiz, questionAmount);


    } catch (JSONException e) {
        e.printStackTrace();
    }


    listView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {

            TextView tv = (TextView)view.findViewById(R.id.tv_1);
            String answerString = tv.getText().toString();

            set.add(answerString);
            Toast.makeText(Game.this, answerString, Toast.LENGTH_SHORT).show();

            Log.w("svarat", set.toString());

        }
    });
}

private void displayQuiz(JSONArray jsona, int amount) throws JSONException {



    gametv.setText(jsona.getJSONObject(0).getString("question"));

    int numberOfAnswers = Integer.parseInt(jsona.getJSONObject(0).getString("n"));

    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> map = new HashMap<String, String>();

    for (int i = 0; i < numberOfAnswers; i++) {


        String qans = jsona.getJSONObject(0).getString(String.valueOf(i+1));

        JSONObject answer = new JSONObject(qans);

        map.put("answerID", answer.getString("answerID"));
        map.put("answer", answer.getString("answer"));


        mylist.add(map);

        map = new HashMap<String, String>();


    }
    SimpleAdapter sadapter = new SimpleAdapter(this, mylist, R.layout.quizlist, new String[] {"answerID","answer"},
            new int[] {R.id.tv_1, R.id.tv_2}); 


    listView.setAdapter(sadapter);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:14:24+00:00Added an answer on June 2, 2026 at 6:14 am

    Have you tried calling notifyDataSetChanged() on your listView?

    ADDITION

    So if everything displays properly for the first question, here is an approach to increment on each answer click.

    int questionNumber = 0;
    ...
    
        ...
        listView.setOnItemClickListener(new OnItemClickListener() {
    
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
                questionNumber++;
                ...
    
                displayQuiz(...);
            }
        }
    
        private void displayQuiz(JSONArray jsona, int amount) throws JSONException {
            gametv.setText(jsona.getJSONObject(questionNumber).getString("question"));
            ...
        }
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the
I am currently running into a problem where an element is coming back from
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.