PDA

View Full Version : Increase the value of TextView where its value is e.g. is 0? CountDown Timer: 10mins



mineko
11-24-2011, 10:58 PM
Good day! XD

I'm Computer Engineering student having my internship and my boss assigned me to make an android application for Basketball Scoreboard which I'm having a hard time for I don't have lot of Java courses.

As of now,I'm confused on how to change the value of the TextView by onclicklistener. And a timer which upon clicking the textview of timer, it will start to count down from e.g. 10 minutes and to pause the timer, clicking the timer's textview again.

My java code looks like this:

public class scoreboardActivity extends Activity {
/** Called when the activity is first created. */
private TextView HScore, VScore, PScore, Foul1, Foul2;
//private Random _rand = new Random();
//handler handler = new handler();
private Handler handler = new Handler();
@Override
public void onCreate(Bundle cute) {
super.onCreate(cute);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);

// If(updateTime()== TRUE)
updateTime();

handler.removeCallbacks(updateTimeTask);
handler.postDelayed(updateTimeTask, 1000);


Button exit =(Button) findViewById(R.id.exit);
exit.setOnClickListener(mExitListener);

Button reset =(Button) findViewById(R.id.reset);
reset.setOnClickListener(mResetListener);

HScore = (TextView)this.findViewById(R.id.hscore); //Home Score
HScore.setOnClickListener(mHscoreListener);

VScore = (TextView)this.findViewById(R.id.vscore); //Visitor Score

VScore.setOnClickListener(vscoreClickListener);

PScore = (TextView)this.findViewById(R.id.pscore); //Period Score
PScore.setOnClickListener(pscoreClickListener);

Foul1 = (TextView)this.findViewById(R.id.hfoul); // HFoul + 1
Foul1.setOnClickListener(foul1ClickListener);

Foul2 = (TextView)this.findViewById(R.id.vfoul); // VFoul + 1
Foul2.setOnClickListener(foul2ClickListener);


}//end of cuteness

private OnClickListener foul1ClickListener = new OnClickListener() {
public void onClick(View v) {
//DO INCREASE
}; };

private OnClickListener foul2ClickListener = new OnClickListener() {
public void onClick(View v) {
//DO INCREASE
}};
private OnClickListener mHscoreListener = new OnClickListener() {
public void onClick(View v) {
//DO INCREASE
}; };

private OnClickListener vscoreClickListener = new OnClickListener() {
public void onClick(View v) {
//DO INCREASE
}};
private OnClickListener pscoreClickListener = new OnClickListener() {
public void onClick(View v) {
//DO INCREASE after timer became 00:00
}};


private OnClickListener mResetListener = new OnClickListener() {
public void onClick(View v) {
onStop(); }; };

private OnClickListener mExitListener = new OnClickListener() {
public void onClick(View v) {
onDestroy(); }; };


protected void onReset() {
super.onDestroy();
//do stuff
}//onReset



private void updateTime() {
//long start = 0;
final TextView time = (TextView) findViewById(R.id.time);
//while(){

final Date currentTime1 = new Date( 15000);
final SimpleDateFormat formatterTime = new SimpleDateFormat( "mm:ss" );
time.setText( formatterTime.format(currentTime1) );

//start++;
//}//while
}


private Runnable updateTimeTask = new Runnable() {
public void run() {
updateTime();
handler.postDelayed(this, 1000);
}
};


@Override
protected void onDestroy() {
super.onDestroy();
System.exit(0);
}//onDestroy

@Override
protected void onResume() {
super.onResume();
handler.removeCallbacks(updateTimeTask);
handler.postDelayed(updateTimeTask, 1000);
}//onResume

@Override
protected void onPause() {
super.onPause();
//do stuff
}//onStop

@Override
protected void onStop() {
super.onStop();
handler.removeCallbacks(updateTimeTask);
}//onStop

}//end of the world


How do you increase the value of TextView where its value is e.g. is 0? And Please help me with the timer.. CountDown Timer with 10 minutes in initialization.



THANKS!