How to Build a Palindrome Checker App in Android Studio? (original) (raw)

Last Updated : 23 Jul, 2025

In this article, we will be building a **Palindrome Checker android app in Android Studio using Java/Kotlin and XML. The app will check whether the entered word is Palindrome or not, if the entered word is a Palindrome then a toast will be displayed having the message "**Yes, it's a palindrome" otherwise Toast's message will be "**No, it's not a palindrome".

Step by Step Implementation

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.

Step 2: Working with the activity_main.xml file

This file contains an EditText view which takes the input from the user, and a Button view, on clicking which the app will check whether the entered word is Palindrome or not. Below is the code for the **activity_main.xml file.

**activity_main.xml:

XML `

<EditText
    android:id="@+id/editText"
    style="@style/Widget.Material3.Button.OutlinedButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="Enter a word"
    android:textColor="@color/black"
    android:textSize="24sp" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="32dp"
    android:text="Check"
    android:textSize="25sp" />

`

Step 3: Working with the MainActivity file

Inside the class MainActivity, we will create a function "**isPalindrome()" which will take a string value as a parameter and returns a Boolean value, it will return **true if the string is Palindrome and if the string is not a Palindrome it will return **false. Now, inside the onCreate function, we will call a setOnClickListener method on **button, inside it, we pass the text value of **editText to "isPalindrome()" function as an argument, if the returned value is **true, we will display a Toast having message "Yes, it's a palindrome" and if the returned value is False, we will display a Toast having the message "No, it's not a palindrome".

Below is the code for the **MainActivity file.

MainActivity.java `

package org.geeksforgeeks.demo;

import android.os.Bundle; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

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

    EditText editText = findViewById(R.id.editText);
    Button button = findViewById(R.id.button);

    button.setOnClickListener(v -> {
        String text = editText.getText().toString();
        if (isPalindrome(text)) {
            Toast.makeText(MainActivity.this, "Yes, it's a palindrome", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(MainActivity.this, "No, it's not a palindrome", Toast.LENGTH_SHORT).show();
        }
    });
}

private boolean isPalindrome(String text) {
    String reverseString = new StringBuilder(text).reverse().toString();
    return text.equalsIgnoreCase(reverseString);
}

}

MainActivity.kt

package org.geeksforgeeks.demo

import android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.Toast import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val editText: EditText = findViewById(R.id.editText)
    val button: Button = findViewById(R.id.button)

    button.setOnClickListener {
        val text = editText.text.toString()
        if (isPalindrome(text)) {
            Toast.makeText(this, "Yes, it's a palindrome", Toast.LENGTH_SHORT).show()
        } else {
            Toast.makeText(this, "No, it's not a palindrome", Toast.LENGTH_SHORT).show()
        }
    }
}

private fun isPalindrome(text: String): Boolean {
    val reverseString = text.reversed()
    return text.equals(reverseString, ignoreCase = true)
}

}

`

Output: