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
}
}
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.
Please feel free to ask any doubts.
Try the following code
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
and so on till 16
In program