• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps HELP! Java App: Add onclicklistener to TextView and Timer

mineko

Lurker
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:

package com;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
//import android.widget.TextView;
//import android.widget.TextView;
import app.scoreboard.R;
//import app.scoreboard.R.id;

public class scoreboardActivity extends Activity {
/** Called when the activity is first created. */
//private TextView HScore;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);

//HScore = (TextView)this.findViewById(id.hscore); //Home Score
//this.addView(HScore);
}
}



I'm using Android 3.2 (emulated). Any help would be greatly appreciated XD :)
T.T help help help
 
I have made a development regarding my program but it seems It really giving me hard time XD 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.

this is the code i have made so far:


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



TY TY TY TY
 
huh. very confusing code. are all the codes from Android library? so you only post methods right? I didn't see where most of the variables come from.
 
I had it declared before the bundle. I have already got what I am asking so the question is closed . thanks for the reply by the way :)
 
Back
Top Bottom