Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

New Forums: Nexus 6 | Nexus Player | Nexus 9
test: Reply
 
LinkBack Thread Tools
Old November 8th, 2010, 05:11 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2010
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Very simple countdown timmer Help!!!

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);

}
};
}

Advertisements
Mikeyfire is offline  
Reply With Quote
sponsored links
Old November 9th, 2010, 12:45 PM   #2 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 18
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default

Take a look at this...

Android Developers Blog: A Stitch in Time
DiscGolfer17 is offline  
Reply With Quote
Old November 9th, 2010, 02:53 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2010
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Definetly not what I`m looking for

I doubt an article from 2007 is going to help ....anyway maybe I can be more specific ...I need to add the following code to the code listed above .When the code below is finished and the counter reads "DONE" i`d like to also add an action that will bring up a dialog box with a button ..that button will bring me back to the main menu

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

public class Countdown extends Activity {
TextView timeDisplay;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
timeDisplay = new TextView(this);
this.setContentView(timeDisplay);
MyCount counter = new MyCount(30000, 1000);
counter.start();
}

public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}

public void onFinish() {
timeDisplay.setText("Done!");
}

public void onTick(long millisUntilFinished) {
timeDisplay.setText("Left: " + millisUntilFinished / 1000);
}
}
}
Mikeyfire is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:56 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.