How to Create a Full-Screen Click Counter App in Android
This tutorial explains step by step how to create a counter app in Android which changes the text of counting on each click.
Please follow the steps below in order to create a counter app in Android:
1.Click on large text and drag it to the center of the screen.
2.Click on button and drag it to the center of the screen.
3.Change the text to ‘0’ and the id to ‘tx’.
4.Add the name of the button as ‘Click Me’.
5.Change the text size – android:textsize=”100sp”.
6.Go to MainActivity.java. Add the following lines –
private int mCounter = 0;
7.Add the button and the text view.
- btn = (Button) findViewById (R.id.bt);
- txv = (TextView) findViewById (R.id.tx);
8.Add the OnClickListener and the mCounter value.
9.Go to activity_main.xml and add a background color. Also, change the color of the text into white.
10.Change the color of the text, background and the size of the text for the button.
11.Go to live view to check the result. Click on the application.
12.As you click on the button, it will show the count corresponding to the number of times you click on the button.