Guest User

Untitled

a guest
Jan 4th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. public class CapitalsActivity extends AppCompatActivity {
  2.     private Button nextButton;
  3.     private int index = 0;
  4.     private TextView questionTextView;
  5.  
  6.     private Questions[] questions = new Questions[]{
  7.             new Questions(R.string.question_france, "Париж"),
  8.             new Questions(R.string.question_sweden, "Стокгольм"),
  9.             new Questions(R.string.question_poland, "Варшава")
  10.     };
  11.  
  12.     private void updateQuestion() {
  13.         int question = questions[index].getTextResId();
  14.         questionTextView.setText(question);
  15.     }
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.capitals);
  21.  
  22.         nextButton = (Button) findViewById(R.id.next_button);
  23.         nextButton.setOnClickListener(new View.OnClickListener() {
  24.             @Override
  25.             public void onClick(View v) {
  26.                 index = (index + 1) % questions.length;
  27.                 updateQuestion();
  28.             }
  29.         });
  30.  
  31.     }
  32.     @Override
  33.     public boolean onOptionsItemSelected(MenuItem item) {
  34.         // Handle action bar item clicks here. The action bar will
  35.         // automatically handle clicks on the Home/Up button, so long
  36.         // as you specify a parent activity in AndroidManifest.xml.
  37.         int id = item.getItemId();
  38.  
  39.         //noinspection SimplifiableIfStatement
  40.         if (id == R.id.action_settings) {
  41.             return true;
  42.         }
  43.  
  44.         return super.onOptionsItemSelected(item);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment