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

Apps Android Code - Recording Taps

Was hoping to get some help. Just need a simple code to record taps on the screen. (Example = Every time i tap the screen, the numbers raise 1, 2, 3, etc.)

Using eclipse to program everything. Thanks for any help.
 
Welcome to Android Forums!:)

I've moved this to the Application Development forum so you get better exposure for your questions.
 
Have a data member in your Activity to store the current click, then in your OnClickListener's onClick() method, increment that count data member. If you are using a TextView to display the current count, you need to call something like myTextView.setText(Integer.toString(myCountVariable)); after you increment the count variable in the onClick() method.
 
hey jon, thx for the reply. I'm still pretty lost. So here's what I got...

I added a "Number" Text View into the Graphical Layout and i called that '@+id/Score'

I added a Button called '@+id/button1'

so far in my java file i have this:

public class Tap_Game_Activity extends Activity {

private Button tapBtn;


@Override

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tapBtn = (Button) findViewById(R.id.button1);


tapBtn.setOnClickListener(new OnClickListener() {


@Override

public void onClick(View v) {
// TODO Auto-generated method stub
THIS IS WHERE I NEED TO PUT THE +1 NUMBER INCREMENT RIGHT?

}
});



My problem is - I dont know the code (I'm totally new at coding, I copied all the above code off of a YouTube video) so when I click that button the Score text field increments by +1 everytime. Thanks so much for any help
 
I believe I figured it out:

public class Tap_Game_Activity extends Activity {


private Button tapBtn;

int scr=1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tapBtn = (Button) findViewById(R.id.button1);

tapBtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
scr=scr+1;
TextView Score = (TextView) findViewById(R.id.Score);
Score.setText(String.valueOf(scr));
}
});
}


Seems to work for me :). Hope that helps anyone with the same issues.
 
Back
Top Bottom