Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CapitalsActivity extends AppCompatActivity {
- private Button nextButton;
- private int index = 0;
- private TextView questionTextView;
- private Questions[] questions = new Questions[]{
- new Questions(R.string.question_france, "Париж"),
- new Questions(R.string.question_sweden, "Стокгольм"),
- new Questions(R.string.question_poland, "Варшава")
- };
- private void updateQuestion() {
- int question = questions[index].getTextResId();
- questionTextView.setText(question);
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.capitals);
- nextButton = (Button) findViewById(R.id.next_button);
- nextButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- index = (index + 1) % questions.length;
- updateQuestion();
- }
- });
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment