Guest User

Untitled

a guest
Jan 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1. package game.questions;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Random;
  7. import java.util.ArrayList;
  8.  
  9. import android.app.Activity;
  10. import android.os.Bundle;
  11. import android.view.View;
  12. import android.widget.Button;
  13. import android.widget.TextView;
  14.  
  15. //import android.content.Intent;
  16.  
  17.  
  18. public class GameQuestions.Activity extends Activity
  19.  
  20. {
  21.        
  22.     /** Called when the activity is first created. */
  23.     @Override
  24.     public void onCreate(Bundle savedInstanceState)
  25.     {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.main);  
  28.  
  29.        
  30.  
  31.         {
  32.         final Button buttonPlay = (Button) findViewById(R.id.buttonPlay);
  33.         buttonPlay.setOnClickListener(new View.OnClickListener()
  34.             {
  35.                 public void onClick(View v)
  36.                 {
  37.                    
  38.                 gameCode();
  39.                 }
  40.         });
  41.     }
  42. }
  43.    
  44.  
  45.    
  46. int i = 0;
  47. TextView w;
  48. TextView m;
  49.  
  50.  
  51. public void gameCode()
  52.     {
  53.         // Perform action on click
  54.         setContentView(R.layout.game);
  55.        
  56.         //Loads the questions to the arrays
  57.         String[] mQuestions = getResources().getStringArray(R.array.mQuestions);
  58.         String[] wQuestions = getResources().getStringArray(R.array.wQuestions);
  59.            
  60.         //experimental with ArrayList
  61.         ArrayList mList = new ArrayList();
  62.         ArrayList wList = new ArrayList();
  63.         Collections.addAll(mList, mQuestions);
  64.         Collections.addAll(wList, wQuestions);
  65.                
  66.         //Takes a random ID from the array
  67.         Random generator = new Random();
  68.         int rndm = generator.nextInt(mQuestions.length);
  69.         int rndw = generator.nextInt(wQuestions.length);
  70.        
  71.        
  72.         String qMan = mQuestions[rndm];
  73.         String qWoman = wQuestions[rndw];
  74.         if(i == 0)
  75.             {
  76.                
  77.                 w = (TextView)findViewById(R.id.textView1);
  78.                 w.setText(qWoman);
  79.                 mList.remove(rndw);
  80.                 i = 1;
  81.                 final Button buttonNext = (Button) findViewById(R.id.buttonNext);
  82.                 buttonNext.setOnClickListener(new View.OnClickListener()
  83.                 {
  84.                     public void onClick(View v)
  85.                     {
  86.                         gameCode();
  87.                     }
  88.                 });
  89.             }
  90.         else
  91.             {
  92.                
  93.                 m = (TextView)findViewById(R.id.textView1);
  94.                 m.setText(qMan);
  95.                 wList.remove(rndm);
  96.                 i = 0;
  97.                 final Button buttonNext = (Button) findViewById(R.id.buttonNext);
  98.                 buttonNext.setOnClickListener(new View.OnClickListener()
  99.                 {
  100.                     public void onClick(View v)
  101.                     {
  102.                         gameCode();
  103.                     }
  104.                 });
  105.            }
  106.      
  107.     }  
  108.  
  109. }
Add Comment
Please, Sign In to add comment