Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. xmlns:tools="http://schemas.android.com/tools"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8.  
  9. android:paddingBottom="@dimen/activity_vertical_margin"
  10. android:paddingLeft="@dimen/activity_horizontal_margin"
  11. android:paddingRight="@dimen/activity_horizontal_margin"
  12. android:paddingTop="@dimen/activity_vertical_margin"
  13. android:orientation="vertical"
  14.  
  15. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  16.  
  17. tools:context=".QuestionsScrollActivity"
  18. tools:showIn="@layout/activity_questions_scroll"
  19. >
  20.  
  21. <ListView
  22. android:id="@+id/listView"
  23. android:layout_width="match_parent"
  24. android:layout_height="wrap_content"
  25. android:choiceMode="none"
  26. android:layout_weight="1"
  27. />
  28.  
  29. <Button
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content"
  32. android:text="Check answers"
  33. android:id="@+id/checkAnswers"
  34. />
  35.  
  36. </LinearLayout>
  37.  
  38. <?xml version="1.0" encoding="utf-8"?>
  39. <LinearLayout
  40. xmlns:android="http://schemas.android.com/apk/res/android"
  41.  
  42. android:orientation="vertical"
  43. android:layout_width="fill_parent"
  44. android:layout_height="wrap_content"
  45. android:layout_alignParentTop="true"
  46. android:layout_alignParentLeft="true"
  47. android:layout_alignParentStart="true"
  48. android:weightSum="1">
  49.  
  50. <TextView
  51. android:id="@+id/questionNumberTextView"
  52. android:layout_width="wrap_content"
  53. android:layout_height="wrap_content"
  54. android:textAppearance="?android:attr/textAppearanceMedium"
  55. android:text=""
  56. android:layout_gravity="center_horizontal" />
  57.  
  58. <TextView
  59. android:layout_width="match_parent"
  60. android:layout_height="wrap_content"
  61. android:textAppearance="?android:attr/textAppearanceMedium"
  62. android:text="Test question"
  63. android:id="@+id/questionTextView"
  64. android:layout_weight="0.17"
  65. android:layout_marginTop="15dp"
  66. android:textSize="24sp"
  67. android:layout_marginBottom="15dp" />
  68.  
  69. <LinearLayout
  70. android:orientation="vertical"
  71. android:layout_width="match_parent"
  72. android:layout_height="wrap_content"
  73. android:layout_gravity="center_horizontal">
  74.  
  75. <RadioGroup
  76. android:id="@+id/radioGroup"
  77. android:layout_width="match_parent"
  78. android:layout_height="match_parent"
  79. >
  80.  
  81. <RadioButton
  82. android:layout_width="wrap_content"
  83. android:layout_height="wrap_content"
  84. android:text="test answer"
  85. android:id="@+id/answerRadioButton1"
  86. android:checked="false"
  87. android:paddingTop="5dp"
  88. android:paddingBottom="5dp" />
  89.  
  90. <RadioButton
  91. android:layout_width="wrap_content"
  92. android:layout_height="wrap_content"
  93. android:text="test answer"
  94. android:id="@+id/answerRadioButton2"
  95. android:checked="false" />
  96.  
  97. <RadioButton
  98. android:layout_width="wrap_content"
  99. android:layout_height="wrap_content"
  100. android:text="test answer"
  101. android:id="@+id/answerRadioButton3"
  102. android:checked="false" />
  103.  
  104. <RadioButton
  105. android:layout_width="wrap_content"
  106. android:layout_height="wrap_content"
  107. android:text="test answer"
  108. android:id="@+id/answerRadioButton4"
  109. android:checked="false" />
  110.  
  111. </RadioGroup>
  112. </LinearLayout>
  113. </LinearLayout>
  114.  
  115. public class QuestionAdapter extends ArrayAdapter<Question> {
  116. public QuestionAdapter(Context context, ArrayList<Question> questions) {
  117. super(context, 0, questions);
  118. }
  119.  
  120. @Override
  121. public View getView(int position, View convertView, ViewGroup parent) {
  122. final Question question = getItem(position);
  123. ViewHolder viewHolder;
  124. if (convertView == null) {
  125. convertView = LayoutInflater.from(getContext()).inflate(R.layout.question, parent, false);
  126. viewHolder = new ViewHolder();
  127. viewHolder.questionNumberTextView = (TextView) convertView.findViewById(R.id.questionNumberTextView);
  128. viewHolder.questionTextView = (TextView) convertView.findViewById(R.id.questionTextView);
  129. viewHolder.radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup);
  130. viewHolder.answerRadioButton1 = (RadioButton) convertView.findViewById(R.id.answerRadioButton1);
  131. viewHolder.answerRadioButton2 = (RadioButton) convertView.findViewById(R.id.answerRadioButton2);
  132. viewHolder.answerRadioButton3 = (RadioButton) convertView.findViewById(R.id.answerRadioButton3);
  133. viewHolder.answerRadioButton4 = (RadioButton) convertView.findViewById(R.id.answerRadioButton4);
  134. convertView.setTag(viewHolder);
  135. } else {
  136. viewHolder = (ViewHolder) convertView.getTag();
  137. }
  138.  
  139.  
  140. List<Answer> answerList = question.getAnswers();
  141.  
  142. if (answerList != null) {
  143. viewHolder.questionNumberTextView.setText("Question # " + (position + 1));
  144. viewHolder.questionTextView.setText(question.getQuestion());
  145. viewHolder.answerRadioButton1.setText(answerList.get(0).getAnswer());
  146. viewHolder.answerRadioButton2.setText(answerList.get(1).getAnswer());
  147. viewHolder.answerRadioButton3.setText(answerList.get(2).getAnswer());
  148. viewHolder.answerRadioButton4.setText(answerList.get(3).getAnswer());
  149.  
  150. }
  151.  
  152. return convertView;
  153. }
  154.  
  155. static class ViewHolder {
  156. TextView questionNumberTextView;
  157. TextView questionTextView;
  158. RadioGroup radioGroup;
  159. RadioButton answerRadioButton1;
  160. RadioButton answerRadioButton2;
  161. RadioButton answerRadioButton3;
  162. RadioButton answerRadioButton4;
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement