I`m trying to develop my first android app..it`s a simple trivia game .On one screen I have a TextViev that shows the question and buttons to choose an answer ....I want to add a countdown timer in another TextView .. here is the code I have ...
I need to know where to add the code for the Countdown Timer.The is driving me crazy ....any help would be appreciated
package com.Tutorial;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.DialogInterface;
public class Question2 extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question2);
// set a click listener on the toast button
Button Button01 = (Button) findViewById(R.id.Button01);
Button01.setOnClickListener(this);
// set a click listener on the alert button
Button Button02 = (Button) findViewById(R.id.Button02);
Button02.setOnClickListener(this);
// set a click listener on the yesno button
Button Button03 = (Button) findViewById(R.id.Button03);
Button03.setOnClickListener(this);
// set a click listener on the progress button
Button Button04 = (Button) findViewById(R.id.Button04);
Button04.setOnClickListener(this);
Button Button05 = (Button)findViewById(R.id.Button05);
Button05.setOnClickListener(this);
}
public void onClick(View view) {
// which button is clicked?
// the Toast button
if (view == findViewById(R.id.Button01)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("incorrect!");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button02)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("incorrect!");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button03)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("CORRECT!");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent Question3Intent = new Intent(Question2.this,Question3.class);
startActivity(Question3Intent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button04)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("incorrect ");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button05)) {
// display the toast popup window
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
}
};
}
I need to know where to add the code for the Countdown Timer.The is driving me crazy ....any help would be appreciated
package com.Tutorial;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.DialogInterface;
public class Question2 extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question2);
// set a click listener on the toast button
Button Button01 = (Button) findViewById(R.id.Button01);
Button01.setOnClickListener(this);
// set a click listener on the alert button
Button Button02 = (Button) findViewById(R.id.Button02);
Button02.setOnClickListener(this);
// set a click listener on the yesno button
Button Button03 = (Button) findViewById(R.id.Button03);
Button03.setOnClickListener(this);
// set a click listener on the progress button
Button Button04 = (Button) findViewById(R.id.Button04);
Button04.setOnClickListener(this);
Button Button05 = (Button)findViewById(R.id.Button05);
Button05.setOnClickListener(this);
}
public void onClick(View view) {
// which button is clicked?
// the Toast button
if (view == findViewById(R.id.Button01)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("incorrect!");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button02)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("incorrect!");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button03)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("CORRECT!");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent Question3Intent = new Intent(Question2.this,Question3.class);
startActivity(Question3Intent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button04)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("incorrect ");
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
finish ();
}
});
// show it
alertbox.show();
}
if (view == findViewById(R.id.Button05)) {
// display the toast popup window
Intent MenuIntent = new Intent(Question2.this,Menu.class);
startActivity(MenuIntent);
}
};
}