Need assistance with onclick [duplicate]




First of all hi, I am building an android app and basicly I want it to count tapping on screen(anywhere), now i tried to put the relative layout to have clickable true and my 1 textview the same, but when i try to start the activity the app crashes, I would like it to show time, lets say 30 seconds and then to count tapps for these 30 seconds.



> XML <RelativeLayout
> xmlns:android="http://ift.tt/nIICcg"
> xmlns:tools="http://ift.tt/LrGmb4"
> android:layout_width="match_parent"
> android:layout_height="match_parent"
> tools:context="com.orion.peky.thetapgame.Game"
> >
>
> <TextView
> android:text="Tap to start"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:layout_centerVertical="true"
> android:layout_centerHorizontal="true"
> android:textSize="50dp"
> android:textColor="#FFFFFFFF"
> android:id="@+id/tekst" />
>
> </RelativeLayout>
>
> MAIN package com.orion.peky.thetapgame;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.view.Menu;
> import android.view.MenuItem;
> import android.view.View;
> import android.widget.TextView;
>
>
> public class Game extends Activity {
>
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity_game);
> }
> TextView tekst=(TextView)findViewById(R.id.tekst);
> int brojac=0;
>
> public void broji(View view){
> brojac=brojac+1;
> tekst.setText("Tapped "+brojac+" times");
> } }

I hope you can help me make this :D

No comments:

Post a Comment