@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Utils.getInstance().customeTitle(this); // initialize the TextView textviewQuestion = (TextView) findViewById(R.id.textViewQuestion); textviewAnswer = (TextView) findViewById(R.id.textViewAnswer); textviewXX = (TextView) findViewById(R.id.textViewXX); textviewYY = (TextView) findViewById(R.id.textViewYY); // Question template title textviewSubject = (TextView) findViewById(R.id.textViewSubject); // Initialize the Button and set the onClickListener for Button buttonLeft = (Button) findViewById(R.id.buttonLeft); buttonLeft.setOnClickListener(this); buttonRight = (Button) findViewById(R.id.buttonRight); buttonRight.setOnClickListener(this); buttonShowAnswer = (Button) findViewById(R.id.buttonAnswer); buttonShowAnswer.setOnClickListener(this); toggleButtonOnOff = (ToggleButton) findViewById(R.id.voice_on_off); // Import and initialize the string-array elements from values folder collectionQuestions = getResources().getStringArray(R.array.collection_questions); collectionAnswers = getResources().getStringArray(R.array.collection_answers); // Set the first question index index = 0; // Get the default answer in TextView. defaultTextviewAnswer = getResources().getString(R.string.answer); // Set the first question in page. textviewQuestion.setText(collectionQuestions[index]); textviewAnswer.setText(defaultTextviewAnswer); textviewXX.setText(String.valueOf(index + 1) + "/"); textviewYY.setText(String.valueOf(collectionQuestions.length)); textviewSubject.setText("Java - Collections"); // Text to speech conversion textToSpeech = Utils.getInstance() .textToSpeechConversion(toggleButtonOnOff, getApplicationContext(), this); Utils.getInstance() .addTextToSpeechListener( toggleButtonOnOff, getApplicationContext(), textviewAnswer, defaultTextviewAnswer); }
@Override public void onClick(View v) { index = Utils.getInstance() .onClickEvent( v, index, textviewAnswer, textviewQuestion, textviewXX, collectionQuestions, collectionAnswers, defaultTextviewAnswer, textToSpeech); }
@Override protected void onDestroy() { super.onDestroy(); Utils.getInstance().stopTextToSpeech(true, textToSpeech); }