2

Im new to android..

Im facing a problem in Nextbutton while displaying the next question...

In my first time set text im getting the correct question and matched four option answers. What i needed is..

I have a nextbutton for displaying the next question and answers..When click on next button i can get the next four options for next question..But i can't get next question after four times i click on next it shows next question...but answers are correct.

What im doing wrong? what im missing?

Any help would be appreciated...Thanks a lot in advance..

      protected String doInBackground(String... args) {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
        System.out.println("cool");
    params.add(new BasicNameValuePair("tid", tid));
    json = jsonParser.makeHttpRequest(url_get_quesurl, "GET", params);
    System.out.println("ques value got");
    Log.d("All Groups: ", json.toString());
        System.out.println("question");
    try {
    int success = json.getInt(TAG_SUCCESS);
    System.out.println("Success");
    if (success == 1) {
    System.out.println("Success");
    groups = json.getJSONArray(TAG_GROUP);
    System.out.println("Result Success+++"+groups);
    for (int i = 0; i < groups.length();i++) {
    JSONObject c = groups.getJSONObject(i);
          String question = c.getString(TAG_QUES);
      System.out.println("Checking ::"+question);
    ques1.add(question);
    String answer = c.getString(TAG_ANSW);
    System.out.println("Checking ::"+answer);
    answ1.add(answer);
           }
        } else {
            showAlert();
        }
    } catch (JSONException e) {
        System.out.println("Error "+e.toString());
    }
    return null;
}  
   protected void onPostExecute(String file_url) {
    pDialog.dismiss();
      ques1=new ArrayList<String>(new ArrayList<String>(ques1));
            //  j=0;
            TextView txtque = (TextView) findViewById(R.id.que_txt); 
            txtque.setText(ques1.get(j));
    answ1=new ArrayList<String>(new ArrayList<String>(answ1));
            btn_practice1.setText(answ1.get(0));
            btn_practice2.setText(answ1.get(1));
            btn_practice3.setText(answ1.get(2));
            btn_practice4.setText(answ1.get(3));
         btn_practicerg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) { 
                    RadioButton radioButton = (RadioButton) findViewById(checkedId);
                   // Toast.makeText(Question.this, "" + radioButton.getText(), 2000).show(); 
                    TextView txtRadio = (TextView) findViewById(R.id.rdtxt); 
                    txtRadio.setText("" + radioButton.getText());
                }
    });
        Button nextBtn = (Button) findViewById(R.id.nxt_btn);
        nextBtn.setOnClickListener(new Button.OnClickListener(){
          public void onClick(View v){  
          j++;
        TextView txtque = (TextView) findViewById(R.id.que_txt); 
        txtque.setText(ques1.get(j)); 
        k++;
        btn_practice1.setText(answ1.get((k*4)+0));
        btn_practice2.setText(answ1.get((k*4)+1));
        btn_practice3.setText(answ1.get((k*4)+2));
        btn_practice4.setText(answ1.get((k*4)+3));
         }
       });
}
10
  • make a custom adapter and using that you can get string form array. Commented Jan 31, 2013 at 11:52
  • How i cant understand..Can you give some example using my code...im new to android..help me Commented Jan 31, 2013 at 12:01
  • where is your question and answer ? using local or web service ? Commented Jan 31, 2013 at 12:04
  • webservice...I got question and answer from JSON object and question are stored in ques1 arrayList and answers are stored in answ1 ArrayList.. Commented Jan 31, 2013 at 12:21
  • Please post the full code i mean how you storing questions? Commented Jan 31, 2013 at 13:00

2 Answers 2

1

The problem is you are storing answers in answ1 array for that time four empty strings adding in ques1 array so you are getting your next question after four times pressing the button....

For that maintain two indexes one for questions and other for answers..

Sign up to request clarification or add additional context in comments.

12 Comments

yes i maintain two indexes only "j" for question and "k" for answers...Its not getting the next question...What im doing wrong really i dont know please help me..frnd..
please give ur webservice link for getting questions and answers?
its not opening in google chrome shows the following error....... Oops! Google Chrome could not connect to 10.0.2.2
How you will open this link, its my path link to file ques_ans1.php. I cant understand your question..What link you need..frnd
where u getting questions and answers
|
1

Make Your Array :

  • ArrayList<String> Question = new ArrayList<String>();
  • ArrayList<String> Answer = new ArrayList<String>();

Add your value :

  • Question.add(json_data.getString("QUESTION_TAG").toString());
  • Answer.add(json_data.getString("ANSWER_TAG").toString());

check List Length and you have to update index in button click.

Button Click Event :

  • Question.get(index).toString();
  • Answer.get(index).toString();

Here you can use your data and update index each time after click and if your answer id true.

Note: your index should be maintain otherwise it will throws indexoutofrangeexception Exception.

Hope you can manage according to this.

4 Comments

okay TAG_QUES & TAG_ANSW is your json code. now as you do add data in loop and then get index in button click event. i don't know where you getting issue ?
See my update...please help me..really i dont know where im doing mistake..what im missing? Im new to android..
solve your issue or still getting issue ? i have give you upvote
see this link and answer me help me plz.. stackoverflow.com/questions/14685873/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.