Create Your First Android App with Complete Examples (To Do List)

Android development is a rewarding skill that allows you to create applications for millions of users worldwide. In this guide, We will guide you step by step how to build an Android app with full code examples. As an example, we will create a To-Do List app that allows users to add and remove tasks.

Prerequisites for Create Your First Android App

Before we start, ensure you have the following installed on your system:

  • Android Studio (latest version)
  • Java Development Kit (JDK)
  • Basic knowledge of Java or Kotlin (we’ll use Java for this tutorial)

Creating a New Android Project

Step 1: Creating a New Android Project

  1. Open Android Studio and click on Start a new Android Studio project.
  2. Select Empty Activity and click Next.
  3. Enter the following details:
    • Name: ToDoListApp
    • Package name: com.example.todolistapp
    • Save location: Choose your desired directory
    • Language: Java
    • Minimum API Level: API 21 (Lollipop)
  4. Click Finish to create your project.

Step 2: Understanding the Project Structure

Your project contains several files and folders:

  • MainActivity.java (Handles the main logic)
  • activity_main.xml (Defines the UI layout)
  • AndroidManifest.xml (Contains app permissions and configurations)
  • Gradle Scripts (Handles dependencies and build settings)

Step 3: Designing the UI (activity_main.xml)

Open res/layout/activity_main.xml and modify it as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <EditText
        android:id="@+id/editTextTask"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter task"/>

    <Button
        android:id="@+id/buttonAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add Task"/>

    <ListView
        android:id="@+id/listViewTasks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

Step 4: Writing Java Code (MainActivity.java)

Now, open MainActivity.java and modify it to handle adding and removing tasks.

package com.example.todolistapp;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    ArrayList<String> taskList;
    ArrayAdapter<String> adapter;

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

        EditText editTextTask = findViewById(R.id.editTextTask);
        Button buttonAdd = findViewById(R.id.buttonAdd);
        ListView listViewTasks = findViewById(R.id.listViewTasks);

        taskList = new ArrayList<>();
        adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskList);
        listViewTasks.setAdapter(adapter);

        buttonAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String task = editTextTask.getText().toString();
                if (!task.isEmpty()) {
                    taskList.add(task);
                    adapter.notifyDataSetChanged();
                    editTextTask.setText("");
                }
            }
        });

        listViewTasks.setOnItemClickListener((parent, view, position, id) -> {
            taskList.remove(position);
            adapter.notifyDataSetChanged();
        });
    }
}

Step 5: Running Your App

  1. Connect your Android device or start an emulator.
  2. Click Run (green play button) in Android Studio.
  3. Your app will launch, allowing users to enter tasks and add them to a list.
  4. Clicking a task in the list will remove it.

Conclusion

Congratulations! You’ve created a simple To-Do List app. You now understand how to set up an Android project, design a UI, and write Java code to manage user interactions. Enhance your app further by adding features like task persistence using databases or notifications.

Happy coding!

If you’re interested in expanding your Android development skills beyond this tutorial, consider building a fully functional mobile app with professional features. Whether it’s a business app, an e-commerce platform, or a custom solution, having expert guidance can make a big difference. Check out our Mobile App & Website Development service at FluxZap, where we help bring your ideas to life with high-quality development solutions. 🚀

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply