daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 52 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. score keeps increasing (old score   current score) , android
  2. public class QuestActivity extends Activity implements OnClickListener{
  3.  
  4. DatabaseUsername helper=null;
  5. private Quest currentQ;
  6. private SetGame currentGame;
  7. private int userId;
  8. public static final String LOG_TAG = "RIKA";
  9.  
  10. @Override
  11. public void onCreate(Bundle savedInstanceState) {
  12.     super.onCreate(savedInstanceState);
  13.     setContentView(R.layout.questactivitylayout);
  14.     currentGame = ((TheApplication)getApplication()).getCurrentGame();
  15.     currentQ = currentGame.getNextQuestion();
  16.     Button nextBtn = (Button) findViewById(R.id.nextBtn);
  17.     final Button confirmBtn = (Button) findViewById(R.id.confirmBtn);
  18.     setQuestions();
  19.  
  20.     helper=new DatabaseUsername(this);
  21.  
  22.     nextBtn.setOnClickListener(new View.OnClickListener() {
  23.     String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
  24.  
  25.         @Override
  26.         public void onClick(View arg0) {
  27.  
  28.             /**
  29.              * check if end of game
  30.              */
  31.             if (currentGame.isGameOver()){
  32.                 helper.insertMark(currentGame.getRight(), QuizAppActivity.number, currentDateTimeString );
  33.                 Log.e(LOG_TAG, "id value "+ userId);
  34.                 Intent i = new Intent(QuestActivity.this, TheEndActivity.class);
  35.                 startActivity(i);
  36.                 finish();
  37.             }
  38.             else{
  39.                 Intent i = new Intent(QuestActivity.this, QuestActivity.class);
  40.                 startActivity(i);
  41.                 finish();
  42.             }
  43.         }
  44.     });
  45.  
  46.     confirmBtn.setOnClickListener(new View.OnClickListener() {
  47.         private boolean clicked = false;
  48.  
  49.         @Override
  50.         public void onClick(View arg0) {
  51.             /**
  52.              * validate a checkbox has been selected
  53.              */
  54.  
  55.                 if(!clicked){
  56.                        clicked = true;      
  57.  
  58.                            // do your processing - one click only
  59.                            if (!checkAnswer())                              
  60.                                 return;
  61.                        }
  62.                 confirmBtn.setVisibility(View.INVISIBLE);
  63.                 confirmBtn.setVisibility(View.GONE);
  64.  
  65.                }
  66.  
  67.  
  68.     });
  69.  
  70.  
  71. }
  72.  
  73.  
  74. private void setQuestions() {
  75.     //set the question text from current question
  76.     String question = ConvAddition.capitalise(currentQ.getQuestion()) + "?";
  77.     TextView qText = (TextView) findViewById(R.id.question);
  78.     qText.setText(question);
  79.  
  80.     //set the available options
  81.     List<String> answers = currentQ.getQuestionOptions();
  82.     TextView option1 = (TextView) findViewById(R.id.answer1);
  83.     option1.setText(ConvAddition.capitalise(answers.get(0)));
  84.  
  85.     TextView option2 = (TextView) findViewById(R.id.answer2);
  86.     option2.setText(ConvAddition.capitalise(answers.get(1)));
  87.  
  88.     TextView option3 = (TextView) findViewById(R.id.answer3);
  89.     option3.setText(ConvAddition.capitalise(answers.get(2)));
  90.  
  91.     TextView option4 = (TextView) findViewById(R.id.answer4);
  92.     option4.setText(ConvAddition.capitalise(answers.get(3)));
  93. }
  94.  
  95.  
  96. @Override
  97. public boolean onKeyDown(int keyCode, KeyEvent event)
  98. {
  99.     switch (keyCode)
  100.     {
  101.     case KeyEvent.KEYCODE_BACK :
  102.         return true;
  103.     }
  104.  
  105.     return super.onKeyDown(keyCode, event);
  106. }
  107.  
  108.  
  109. private boolean checkAnswer() {
  110.  
  111.     TextView checkAnsText = (TextView) findViewById(R.id.checkAns);
  112.  
  113.     String answer = getSelectedAnswer();
  114.     if (answer==null){
  115.         return false;
  116.     }
  117.     else {
  118.             if (currentQ.getAnswer().equalsIgnoreCase(answer))
  119.         {
  120.                 currentGame.incrementRightAnswers();
  121.                 checkAnsText.setText ("Correct Answer " + answer);
  122.                 Log.e("Correct Answer", answer, null);
  123.  
  124.         }
  125.         else{
  126.                 currentGame.incrementWrongAnswers();
  127.                 checkAnsText.setText ("Wrong Answer " + answer);
  128.                  Log.e("Wrong Answer", answer, null);
  129.  
  130.         }
  131.         return true;
  132.     }
  133. }
  134.  
  135.  
  136. private String getSelectedAnswer() {
  137.     RadioButton c1 = (RadioButton)findViewById(R.id.answer1);
  138.     RadioButton c2 = (RadioButton)findViewById(R.id.answer2);
  139.     RadioButton c3 = (RadioButton)findViewById(R.id.answer3);
  140.     RadioButton c4 = (RadioButton)findViewById(R.id.answer4);
  141.     if (c1.isChecked())
  142.     {
  143.         return c1.getText().toString();
  144.     }
  145.     if (c2.isChecked())
  146.     {
  147.         return c2.getText().toString();
  148.     }
  149.     if (c3.isChecked())
  150.     {
  151.         return c3.getText().toString();
  152.     }
  153.     if (c4.isChecked())
  154.     {
  155.         return c4.getText().toString();
  156.     }
  157.  
  158.     return null;
  159. }
  160.  
  161.  
  162. @Override
  163. public void onClick(View arg0) {
  164.     // TODO Auto-generated method stub
  165.  
  166. }}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top