Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. public class RecyclerViewAdapter extends PagerAdapter {
  2. // Declare Variables
  3. Context context;
  4. LayoutInflater inflater;
  5. public List<questions> list;
  6.  
  7.  
  8.  
  9. public RecyclerViewAdapter(Context context, List<questions> TempList) {
  10. this.context = context;
  11. this.list = TempList;
  12. }
  13.  
  14. @Override
  15. public int getCount() {
  16. return list.size();
  17. }
  18.  
  19. @Override
  20. public boolean isViewFromObject(View view, Object object) {
  21. return view == ((RelativeLayout) object);
  22. }
  23.  
  24. @Override
  25. public Object instantiateItem(final ViewGroup container, final int position) {
  26.  
  27. // Declare Variables
  28. final Button option1,option2,option3,option4;
  29. final TextView question,total_question,hindi_question,mark;
  30. inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  31. final View itemView = inflater.inflate(R.layout.quiz_layout_listview, container,
  32. false);
  33.  
  34. // Locate the TextViews in viewpager_item.xml
  35. question = (TextView)itemView.findViewById(R.id.question);
  36. option1 = (Button) itemView.findViewById(R.id.optiona);
  37. option2 = (Button) itemView.findViewById(R.id.optionb);
  38. option3 = (Button) itemView.findViewById(R.id.optionc);
  39. option4 = (Button) itemView.findViewById(R.id.optiond);
  40. total_question=(TextView)itemView.findViewById(R.id.total_question);
  41. hindi_question=(TextView)itemView.findViewById(R.id.hindi_question);
  42. mark=(TextView)itemView.findViewById(R.id.mark_question);
  43.  
  44.  
  45.  
  46.  
  47. total_question.setText(String.valueOf(list.get(position)));
  48.  
  49. final questions studentDetails = list.get(position);
  50.  
  51. question.setText(studentDetails.getQuestion());
  52. option1.setText(studentDetails.getOption1());
  53. option2.setText(studentDetails.getOption2());
  54. option3.setText(studentDetails.getOption3());
  55. option4.setText(studentDetails.getOption4());
  56. hindi_question.setText(studentDetails.getHindi_Question());
  57.  
  58.  
  59. change_language.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  60. @Override
  61. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  62. if (isChecked){
  63.  
  64. chk="check";
  65. question.setText(studentDetails.getHindi_Question());
  66.  
  67. }
  68. else {
  69. chk="";
  70. question.setText(studentDetails.getQuestion());
  71. }
  72. }
  73. });
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. Question_No=position;
  84. Question_No++;
  85.  
  86.  
  87. total_question.setText(String.valueOf("Q."+Question_No));
  88.  
  89.  
  90.  
  91. final String ans=studentDetails.getAnswer().toString();
  92.  
  93. option1.setOnClickListener(new View.OnClickListener() {
  94. @Override
  95. public void onClick(View v) {
  96. option1.setEnabled(false);
  97. option2.setEnabled(false);
  98. option3.setEnabled(false);
  99. option4.setEnabled(false);
  100.  
  101. if (ans.equals("A")) {
  102. option1.setBackgroundResource(R.drawable.correct);
  103. //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
  104. }
  105. else {
  106. option1.setBackgroundResource(R.drawable.wrong);
  107. if (ans.equals("B")) {
  108. option2.setBackgroundResource(R.drawable.correct);
  109. //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  110. }
  111. else if (ans.equals("C")) {
  112. option3.setBackgroundResource(R.drawable.correct);
  113. //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  114. }
  115. else if (ans.equals("D")) {
  116. option4.setBackgroundResource(R.drawable.correct);
  117. //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  118. }
  119. }
  120.  
  121. }
  122. });
  123. option2.setOnClickListener(new View.OnClickListener() {
  124. @Override
  125. public void onClick(View v) {
  126. option1.setEnabled(false);
  127. option2.setEnabled(false);
  128. option3.setEnabled(false);
  129. option4.setEnabled(false);
  130. if (ans.equals("B")) {
  131. option2.setBackgroundResource(R.drawable.correct);
  132. //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
  133. }
  134. else {
  135. option2.setBackgroundResource(R.drawable.wrong);
  136. if (ans.equals("A")) {
  137. option1.setBackgroundResource(R.drawable.correct);
  138. //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  139. }
  140. else if (ans.equals("C")) {
  141. option3.setBackgroundResource(R.drawable.correct);
  142. // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  143. }
  144. else if (ans.equals("D")) {
  145. option4.setBackgroundResource(R.drawable.correct);
  146. // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  147. }
  148. }
  149. }
  150. });
  151. option3.setOnClickListener(new View.OnClickListener() {
  152. @Override
  153. public void onClick(View v) {
  154. option1.setEnabled(false);
  155. option2.setEnabled(false);
  156. option3.setEnabled(false);
  157. option4.setEnabled(false);
  158. if (ans.equals("C")) {
  159. option3.setBackgroundResource(R.drawable.correct);
  160. //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
  161. }
  162. else {
  163. option3.setBackgroundResource(R.drawable.wrong);
  164. if (ans.equals("A")) {
  165. option1.setBackgroundResource(R.drawable.correct);
  166. //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  167. }
  168. else if (ans.equals("B")) {
  169. option2.setBackgroundResource(R.drawable.correct);
  170. //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  171. }
  172. else if (ans.equals("D")) {
  173. option4.setBackgroundResource(R.drawable.correct);
  174. //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  175. }
  176. }
  177. }
  178. });
  179. option4.setOnClickListener(new View.OnClickListener() {
  180. @Override
  181. public void onClick(View v) {
  182. option1.setEnabled(false);
  183. option2.setEnabled(false);
  184. option3.setEnabled(false);
  185. option4.setEnabled(false);
  186. if (ans.equals("D")) {
  187. option4.setBackgroundResource(R.drawable.correct);
  188. //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
  189. }
  190. else {
  191. option4.setBackgroundResource(R.drawable.wrong);
  192. if (ans.equals("A")) {
  193. option1.setBackgroundResource(R.drawable.correct);
  194. // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  195. }
  196. else if (ans.equals("B")) {
  197. option2.setBackgroundResource(R.drawable.correct);
  198. // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  199. }
  200. else if (ans.equals("C")) {
  201. option3.setBackgroundResource(R.drawable.correct);
  202. // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
  203. }
  204. }
  205. }
  206. });
  207.  
  208. save_next.setOnClickListener(new View.OnClickListener() {
  209. @Override
  210. public void onClick(View v) {
  211.  
  212. viewPager.setCurrentItem(getItem(+1), true);
  213.  
  214. }
  215. });
  216.  
  217.  
  218.  
  219. ((ViewPager) container).addView(itemView);
  220.  
  221. return itemView;
  222.  
  223. }
  224.  
  225. @Override
  226. public void destroyItem(ViewGroup container, int position, Object object) {
  227. // Remove viewpager_item.xml from ViewPager
  228. ((ViewPager) container).removeView((RelativeLayout) object);
  229. }
  230. private int getItem(int i) {
  231. return viewPager.getCurrentItem() + i;
  232.  
  233. }
  234.  
  235.  
  236. private int getItem2(int i) {
  237. return list.size();
  238.  
  239. }
  240.  
  241. public int getItemPosition(Object object) {
  242.  
  243.  
  244. return POSITION_NONE;
  245. }
  246.  
  247.  
  248.  
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement