Open In App

How to Build a Simple Notes App in Android?

Last Updated : 20 Feb, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Notes app is used for making short text notes, updating when you need them, and trashing when you are done. It can be used for various functions as you can add your to-do list in this app, some important notes for future reference, etc. The app is very useful in some cases like when you want quick access to the notes. Likewise, here let’s create an Android App to learn how to create a simple Notes App. So in this article let’s build a Notes App in which the user can add any data, remove any data as well as open any data.

Note that we are going to implement this project using both Java and Kotlin language. 

Resources Used in the Application

In this Application, we will be using Activities and Simple Java/Kotlin Code:

  • Main Activity: The Main Activity is used for Activities on the Main Page.
  • Detail Activity: Detail Activity is used for Details of the Notes Opened using the Open Button.
  • Add Note Activity: The Add Note Activity is used for Creating new Entries in the Data.
  • My Adapter: It is an Adapter for the list view used for Defining the Structure of Every Single List Item.

Layouts Used in this Application:

  • activity_main: The layout of the main page is used here.
  • list_item: The layout for the list item which is used in the main activity is mentioned here.
  • activity_detail: The layout for the window where we will be opening the Notes in Full Page in the CardView
  • activity_add_note: The layout for the window where we can add the new item on the main page.

Directory Structure of the Application

dir-notes-app


Steps for Creating a Notes Application on Android

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Note: Select Java/Kotlin as the programming language.

Step 2: Working with the MainActivity and it’s layout file

In the activity_main.xml file the main page we will only display the Notes with Add , Open and Delete Button.

MainActivity.java
package org.geeksforgeeks.simple_notes_application_java;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_CODE_ADD_NOTE = 1;
    private MyAdapter adapter;
    private List<String> items;

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

        ListView listView = findViewById(R.id.listView);
        Button addNoteButton = findViewById(R.id.add_button);

        // Initialize the list of items
        items = new ArrayList<>();

        // Add a temporary item
        items.add("Temp Add Element");

        // Create the adapter and set it to the ListView
        adapter = new MyAdapter(this, items);
        listView.setAdapter(adapter);

        // Set click listener for the add note button
        addNoteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, AddNoteActivity.class);
                startActivityForResult(intent, REQUEST_CODE_ADD_NOTE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_CODE_ADD_NOTE && resultCode == RESULT_OK) {
            String newNote = data.getStringExtra("NEW_NOTE");
            if (newNote != null) {
                items.add(newNote);
                adapter.notifyDataSetChanged();
            }
        }
    }
}
MainActivity.kt activity_main.xml

Design UI:

notes-main


Step 3: Create an Adapter and it’s Layout file

Apart from this we will need a Layout template for every List Item. So, we will be creating a new Layout File. Also, we need a Program to Support the MainAcitivity for adding the functionalities to ListView Items i.e. Add Button and Delete Button. Create MyAdapter Class containing the Functionalities. Create New Java/Kotlin Class MyAdapter file in the main src project in the same repo as MainActivity file:

File Name: list_item.xml and MyAdapter.kt/.java

MyAdapter.java
package org.geeksforgeeks.simple_notes_application_java;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

public class MyAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final List<String> values;

    public MyAdapter(Context context, List<String> values) {
        super(context, R.layout.list_item, values);
        this.context = context;
        this.values = values;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_item, parent, false);

        TextView textView = rowView.findViewById(R.id.textView);
        Button openButton = rowView.findViewById(R.id.button);
        Button deleteButton = rowView.findViewById(R.id.delete_button);

        textView.setText(values.get(position));

        openButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Start DetailActivity and pass the item data
                Intent intent = new Intent(context, DetailActivity.class);
                intent.putExtra("ITEM", values.get(position));
                context.startActivity(intent);
            }
        });

        deleteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "Delete button clicked for item " + values.get(position), Toast.LENGTH_SHORT).show();
                // Remove the item from the list
                values.remove(position);
                // Notify the adapter to refresh the list view
                notifyDataSetChanged();
            }
        });

        return rowView;
    }
}
MyAdapter.kt list_item.xml

Design UI:

notes-list-item

Step 4: Creating New Layouts for Opening the Details and Adding the Items.

Go to app > java/kotlin > right-click > New > Activity > Empty Activity and name it as AddNoteActivity.

Note: Similarly Create DetailActivity.

Resource File Created :

  1. AddNoteActivity.java/.kt and activity_add_note.xml
  2. DetailActivity.java/.kt and activity_detail_activity.xml

Below is the code for AddNoteActivity:

AddNoteActivity.java
package org.geeksforgeeks.simple_notes_application_java;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class AddNoteActivity extends AppCompatActivity {

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

        EditText editText = findViewById(R.id.editTextNote);
        Button buttonAdd = findViewById(R.id.buttonAddNote);

        buttonAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String newNote = editText.getText().toString().trim();
                if (!newNote.isEmpty()) {
                    Intent resultIntent = new Intent();
                    resultIntent.putExtra("NEW_NOTE", newNote);
                    setResult(RESULT_OK, resultIntent);
                    finish();
                }
            }
        });
    }
}
AddNoteActivity.kt activity_add_note.xml

Design UI:

notes-add-note

And the code for DetailActivity:

DetailActivity.java
package org.geeksforgeeks.simple_notes_application_java;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class DetailActivity extends AppCompatActivity {

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

        TextView detailTextView = findViewById(R.id.detailTextView);
        TextView dataNotesTextView = findViewById(R.id.Data_Notes);

        // Get the data passed from MainActivity
        String item = getIntent().getStringExtra("ITEM");

        // Set the data to the TextViews
        detailTextView.setText("Notes Content");
        dataNotesTextView.setText(item);
    }
}
DetailActivity.kt activity_detail.xml

Design UI:

notes-details

Output:

Final Application to Build a Simple Notes App


Note: The Application we have created is like a template for your Notes Application you can make changes in it as you want.

The GitHub Link for the Application is : Click Here to access the Complete Code to create a Simple Notes Application



Next Article

Similar Reads

three90RightbarBannerImg