Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RecyclerViewAdapter extends PagerAdapter {
- // Declare Variables
- Context context;
- LayoutInflater inflater;
- public List<questions> list;
- public RecyclerViewAdapter(Context context, List<questions> TempList) {
- this.context = context;
- this.list = TempList;
- }
- @Override
- public int getCount() {
- return list.size();
- }
- @Override
- public boolean isViewFromObject(View view, Object object) {
- return view == ((RelativeLayout) object);
- }
- @Override
- public Object instantiateItem(final ViewGroup container, final int position) {
- // Declare Variables
- final Button option1,option2,option3,option4;
- final TextView question,total_question,hindi_question,mark;
- inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- final View itemView = inflater.inflate(R.layout.quiz_layout_listview, container,
- false);
- // Locate the TextViews in viewpager_item.xml
- question = (TextView)itemView.findViewById(R.id.question);
- option1 = (Button) itemView.findViewById(R.id.optiona);
- option2 = (Button) itemView.findViewById(R.id.optionb);
- option3 = (Button) itemView.findViewById(R.id.optionc);
- option4 = (Button) itemView.findViewById(R.id.optiond);
- total_question=(TextView)itemView.findViewById(R.id.total_question);
- hindi_question=(TextView)itemView.findViewById(R.id.hindi_question);
- mark=(TextView)itemView.findViewById(R.id.mark_question);
- total_question.setText(String.valueOf(list.get(position)));
- final questions studentDetails = list.get(position);
- question.setText(studentDetails.getQuestion());
- option1.setText(studentDetails.getOption1());
- option2.setText(studentDetails.getOption2());
- option3.setText(studentDetails.getOption3());
- option4.setText(studentDetails.getOption4());
- hindi_question.setText(studentDetails.getHindi_Question());
- change_language.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (isChecked){
- chk="check";
- question.setText(studentDetails.getHindi_Question());
- }
- else {
- chk="";
- question.setText(studentDetails.getQuestion());
- }
- }
- });
- Question_No=position;
- Question_No++;
- total_question.setText(String.valueOf("Q."+Question_No));
- final String ans=studentDetails.getAnswer().toString();
- option1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- option1.setEnabled(false);
- option2.setEnabled(false);
- option3.setEnabled(false);
- option4.setEnabled(false);
- if (ans.equals("A")) {
- option1.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
- }
- else {
- option1.setBackgroundResource(R.drawable.wrong);
- if (ans.equals("B")) {
- option2.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("C")) {
- option3.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("D")) {
- option4.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- option2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- option1.setEnabled(false);
- option2.setEnabled(false);
- option3.setEnabled(false);
- option4.setEnabled(false);
- if (ans.equals("B")) {
- option2.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
- }
- else {
- option2.setBackgroundResource(R.drawable.wrong);
- if (ans.equals("A")) {
- option1.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("C")) {
- option3.setBackgroundResource(R.drawable.correct);
- // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("D")) {
- option4.setBackgroundResource(R.drawable.correct);
- // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- option3.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- option1.setEnabled(false);
- option2.setEnabled(false);
- option3.setEnabled(false);
- option4.setEnabled(false);
- if (ans.equals("C")) {
- option3.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
- }
- else {
- option3.setBackgroundResource(R.drawable.wrong);
- if (ans.equals("A")) {
- option1.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("B")) {
- option2.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("D")) {
- option4.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- option4.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- option1.setEnabled(false);
- option2.setEnabled(false);
- option3.setEnabled(false);
- option4.setEnabled(false);
- if (ans.equals("D")) {
- option4.setBackgroundResource(R.drawable.correct);
- //Toast.makeText(Previous_Yr_Quiz.this, "True", Toast.LENGTH_SHORT).show();
- }
- else {
- option4.setBackgroundResource(R.drawable.wrong);
- if (ans.equals("A")) {
- option1.setBackgroundResource(R.drawable.correct);
- // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("B")) {
- option2.setBackgroundResource(R.drawable.correct);
- // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- else if (ans.equals("C")) {
- option3.setBackgroundResource(R.drawable.correct);
- // Toast.makeText(Previous_Yr_Quiz.this, "false", Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- save_next.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- viewPager.setCurrentItem(getItem(+1), true);
- }
- });
- ((ViewPager) container).addView(itemView);
- return itemView;
- }
- @Override
- public void destroyItem(ViewGroup container, int position, Object object) {
- // Remove viewpager_item.xml from ViewPager
- ((ViewPager) container).removeView((RelativeLayout) object);
- }
- private int getItem(int i) {
- return viewPager.getCurrentItem() + i;
- }
- private int getItem2(int i) {
- return list.size();
- }
- public int getItemPosition(Object object) {
- return POSITION_NONE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement