Build Your Own Web Click Counter and Turn It into an APK

In this article, I'll walk you through the process of creating your own click counter using HTML and JavaScript, and then show you how to convert it into an Android application (APK) using Android Studio.

5/8/20254 min read

Click Counter Web App Icon
Click Counter Web App Icon

Click Counter APK

This app is an APK, only for Android.

It allows you to count people or anything else, and can increase or decrease the number.

You can specify the amount to increase with each click.

Click the button below to download and then install it on your Android device:

Screenshots

Counter Apk screen
Counter Apk screen
First Screenshot of Clic Counter APK Application
First Screenshot of Clic Counter APK Application
Build Your Own Web Click Counter and Turn It into an APK

Introduction

In the world of web development, sometimes the simplest tools can be the most useful. A click counter is a fundamental project that not only helps you understand the basics of HTML and JavaScript, but can also have practical applications, such as counting event attendance or keeping track of any type of repeating event. In this article, I'll walk you through the process of creating your own click counter using HTML and JavaScript, and then show you how to convert it into an Android application (APK) using Android Studio.

What are we going to build?

Our click counter application will have the following features:

• A button to increment the count.

• A button to decrement the count.

• A button to reset the count.

• A display showing the current number of clicks.

• A field for the user to enter how much the counter will increment or decrement each time the button is pressed.

• Visual and vibration feedback when clicking the buttons.

Step 1: Structure with HTML

HTML defines the structure of our website. Here is the basic HTML code:

HTML Explanation

• <head>: Contains information about the page, such as the title (<title>Click Counter</title>), viewport settings (<meta name="viewport" ...>), and CSS styles.

• <body>: Contains the visible content of the page.

• <div>: Used to group elements. Here, the "content" class helps organize the buttons, the counter display, and the input field.

• <button>: Creates the buttons to increment, decrement, and reset the counter. The onclick attribute calls the corresponding JavaScript function when the button is clicked.

• <input type="number">: Creates an input field where the user can enter the value to increment/decrement.

• <strong id="counter">0</strong>: Displays the current value of the counter. The id="counter" allows us to easily access this element with JavaScript.

• <script>: Contains the JavaScript code that adds logic to the page.

• CSS styles, whether internal (<style>) or external (<link rel="stylesheet" href="styles.css">), control the appearance of elements, including colors, fonts, spacing, and responsive design using media queries.

Step 2: Logic with JavaScript

JavaScript is the programming language that makes our website interactive.

javascript

function incrementar() {

var incremento = parseInt(document.getElementById("campoIncremento").value, 10);

let contador = document.getElementById("contador");

contador.textContent = parseInt(contador.textContent) + incremento;

navigator.vibrate(30);

}


function restar() {

var incremento = parseInt(document.getElementById("campoIncremento").value, 10);

let contador = document.getElementById("contador");

contador.textContent = parseInt(contador.textContent) - incremento;

navigator.vibrate(30);

}


function reiniciar() {

document.getElementById("contador").textContent = 0;

navigator.vibrate(30);

}


document.getElementById('botonVibrante').addEventListener('click', function() {

this.classList.add('vibrando');

setTimeout(() => {

this.classList.remove('vibrando');

}, 600);

}

);

JavaScript Explanation

• incrementar():

◦ Gets the value of the input field incrementField using document.getElementById() and converts it to an integer using parseInt().

◦ Gets the element with id="counter" to display the count.

◦ Updates the contents of the counter element by adding the increment value.

• navigator.vibrate(30): Vibrates the device (if supported) for 30 milliseconds to provide haptic feedback.

• restar(): Works similarly to increment(), but subtracts the input field's value from the counter.

reiniciar(): Sets the contents of the counter element to 0.

• The addEventListener adds a visual vibration effect to the button when it is clicked.

Step 3: Styling with CSS (Optional)

CSS allows us to style our page. In the code, styles are included within the <style> tag. You can use an external styles.css file to keep your code more organized. The provided code includes a background gradient, styles for the buttons, input field, and counter, and media queries to make the page responsive to different screen orientations.

Step 4: Converting the Web App to an APK with Android Studio

This is a more advanced step and will require you to have Android Studio installed. Here's a general overview of the process:

1. Create a new project in Android Studio: Select an "Empty Activity" project or similar.

2. Add a WebView: A WebView is an Android component that can display web pages. Add a WebView to your layout (your app's user interface).

3. Upload your HTML: In your Java (or Kotlin) code, load your click counter's HTML file into the WebView. You can place your HTML, CSS, and JavaScript in the assets folder of your Android Studio project.

4. Configure permissions: Make sure your app has the necessary permissions, such as the vibration permission.

5. Build the APK: Android Studio will allow you to build an APK file that you can install on Android devices.

Conclusion

Congratulations! You've built a click counter app from scratch using HTML, JavaScript, and (optionally) CSS. You've also learned the basic steps for converting a web app into an APK using Android Studio. This is a great starting point for exploring more complex web projects and taking your development skills to the next level.

Send your feedback: