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 9181743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:23:32+00:00 2026-06-17T18:23:32+00:00

I’m new to Android. I am facing problem with array list.The problem is, My

  • 0

I’m new to Android.

I am facing problem with array list.The problem is,

My arrays are string array list.
What i need is? I have two array list. QtnsArraylist1 contains 4 elements(4 questions) and AnsArraylist2 contains 16 elements( 16 Answers, for each question 4 options totally 16 elements).For my first Question in QtnsArraylist1 i have to get first 4 elements from AnsArraylist2.Similarly for 2,3,4 questions if give next button .How i can get? .

Please help me some one.

Thanks in Advance.

      D/TAG(910): 1
      D/TAG(910): 2
      D/TAG(910): 3
      D/TAG(910): 4
      D/TAG(910): 5
      D/TAG(910): 6
      D/TAG(910): 1
      D/TAG(910): 2
      D/TAG(910): 3
      D/TAG(910): 4
      D/TAG(910): 5
      D/TAG(910): 6
      D/TAG(910): 1
      D/TAG(910): 2
      D/TAG(910): 3
      D/TAG(910): 4
      D/TAG(910): 5
      D/TAG(910): 6
      D/TAG(910): 1
      D/TAG(910): 2
      D/TAG(910): 3
      D/TAG(910): 4
      D/TAG(910): 5
      D/TAG(910): 6
      D/TAG(910): 1
      D/TAG(910): 2
      D/TAG(910): 3
      D/TAG(910): 4
      D/TAG(910): 5
      D/TAG(910): 6
      D/AndroidRuntime(910): Shutting down VM
      W/dalvikvm(910): threadid=1: thread exiting with uncaught exception 
      (group=0x40015560)
      E/AndroidRuntime(910): FATAL EXCEPTION: main
      E/AndroidRuntime(910): java.lang.IndexOutOfBoundsException: Invalid index 16, size 
      is 16
      E/AndroidRuntime(910):    at 
      java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
      E/AndroidRuntime(910):    at java.util.ArrayList.get(ArrayList.java:311)

code

     protected void onPostExecute(String file_url) {
        pDialog.dismiss();  
        for ( int i = 0,j = 0; i < ques1.size(); i++) {
            String s1 = ques1.get(i).toString();
            Log.d("TAG", "1");
            TextView txtque = (TextView) findViewById(R.id.que_txt); 
            txtque.setText(s1);
            Log.d("TAG", "2");
            btn_practicerg =(RadioGroup) findViewById(R.id.rdgroup);
            Log.d("TAG", "3");
            btn_practice1 = (RadioButton) findViewById(R.id.RB1);
            Log.d("TAG", "4");
            btn_practice2 = (RadioButton) findViewById(R.id.RB2);
            Log.d("TAG", "5");
            btn_practice3 = (RadioButton) findViewById(R.id.RB3);
            Log.d("TAG", "6");
            btn_practice4 = (RadioButton) findViewById(R.id.RB4);
            String s2 = answ1.get(j++);
            btn_practice1.setText(s2);
            String s3 = answ1.get(j++);
            btn_practice1.setText(s3);
            String s4 = answ1.get(j++);
            btn_practice1.setText(s4);
            String s5 = answ1.get(j++);   
            btn_practice1.setText(s5);
            //Display them
        }     
    }
  • 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-17T18:23:33+00:00Added an answer on June 17, 2026 at 6:23 pm

    I could not exactly get what is your problem. If you want to display an element from ArrayList1 followed by 4 elements of ArrayList2 then its quite simple.

    for ( int i = 0,j = 0; i < ArrayList1.size(); i++) {
        s1 = ArrayList1.get(i);
        s2 = ArrayList2.get(j++);
        s3 = ArrayList2.get(j++);
        s4 = ArrayList2.get(j++);
        s5 = ArrayList2.get(j++);   
        //Display them
    }     
    

    Please feel free to ask any doubts.

    Try the following code

    Log.d("TAG", "onCreate() entered");
        setContentView(R.layout.activity_main);
        ArrayList<String> questionsList = new ArrayList<String>();
        ArrayList<String> answersList = new ArrayList<String>();
    
        //Initializing the arrayLists
        for (int index = 0; index < 4; index++) {
            questionsList.add("ques" + index + 1);
        }
        for (int index = 0; index < 16; index++) {
            answersList.add("ans" + index + 1);
        }
    
        //Output
        for (int questionIndex = 0, answerIndex = 0; questionIndex < questionsList.size(); questionIndex++) {
            Log.d("TAG", questionsList.get(questionIndex));
    
            Log.d("TAG", answersList.get(answerIndex++));
            Log.d("TAG", answersList.get(answerIndex++));
            Log.d("TAG", answersList.get(answerIndex++));
            Log.d("TAG", answersList.get(answerIndex++));
    
        }
    

    I am appending the method to set into radioBtn and textViews.

    In the layout file
    set textView ids
    “@+id/questionView1”
    “@+id/questionView2”
    and so on, the radioBtns as

     "@+id/radioBtn1"
     "@+id/radioBtn2" 
    

    and so on till 16

    In program

     for (int questionIndex = 0, answerIndex = 0; questionIndex < questionsList.size(); questionIndex++) {
            TextView tv = (TextView) findViewById(R.id.questionView + questionIndex + 1);
            tv.setText(questionsList.get(questionIndex));
    
            RadioButton rb1 = (RadioButton) findViewById(R.id.radioBtn + answerIndex + 1);
            rb1.setText(answersList.get(answerIndex++));
    
            RadioButton rb2 = (RadioButton) findViewById(R.id.radioBtn + answerIndex + 1);
            rb2.setText(answersList.get(answerIndex++));
    
            RadioButton rb3 = (RadioButton) findViewById(R.id.radioBtn + answerIndex + 1);
            rb3.setText(answersList.get(answerIndex++));
    
            RadioButton rb4 = (RadioButton) findViewById(R.id.radioBtn + answerIndex + 1);
            rb4.setText(answersList.get(answerIndex++));
    
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an array which has BIG numbers and small numbers in it. I
I've tracked down a weird MySQL problem to the two different ways I was
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
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

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.