Skip to main content

Simple Calculator in Android

You can view new updated simple calculator with ViemModel and LiveData in my new blog  
https://androidtuts4u.blogspot.com/2021/10/simple-calculator-with-viewmodel-and.html


To create a calculator first  we need to create the layout of the calculator.
Layout  is created  using XML file given below


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent" >



 <EditText

    android:id="@+id/result_id"   

    android:layout_width="fill_parent"

    android:layout_height="120dp"

  />

 <Button

   android:id="@+id/Btn7_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/result_id"

   android:text="7"

   android:onClick="btn7Clicked"

  />

 <Button

   android:id="@+id/Btn8_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/result_id"

   android:layout_toRightOf="@id/Btn7_id"

   android:text="8"

   android:onClick="btn8Clicked"

  />

  <Button

   android:id="@+id/Btn9_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/result_id"

   android:layout_toRightOf="@id/Btn8_id"

   android:text="9"

   android:onClick="btn9Clicked"

  />

  <Button

   android:id="@+id/Btnclear_id"   

   android:layout_width="90dp"

   android:layout_height="60dp"

   android:layout_below="@id/result_id"

   android:layout_toRightOf="@id/Btn9_id"

   android:text="clear"

   android:onClick="btnclearClicked"

  />

  <Button

   android:id="@+id/Btn4_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn7_id"

   android:text="4"

   android:onClick="btn4Clicked"

  /> <Button

   android:id="@+id/Btn5_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn8_id"

   android:layout_toRightOf="@id/Btn4_id"

   android:text="5"

   android:onClick="btn5Clicked"

  /> <Button

   android:id="@+id/Btn6_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn9_id"

   android:layout_toRightOf="@id/Btn5_id"

   android:text="6"

   android:onClick="btn6Clicked"

  />

  <Button

   android:id="@+id/Btnplus_id"   

   android:layout_width="90dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btnclear_id"

   android:layout_toRightOf="@id/Btn6_id"

   android:text="+"

   android:onClick="btnplusClicked"

  />

  <Button

   android:id="@+id/Btn1_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn4_id"

   android:text="1"

   android:onClick="btn1Clicked"

  /> <Button

   android:id="@+id/Btn2_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn5_id"

   android:layout_toRightOf="@id/Btn1_id"

   android:text="2"

   android:onClick="btn2Clicked"

  /> <Button

   android:id="@+id/Btn3_id"   

   android:layout_width="70dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn6_id"

   android:layout_toRightOf="@id/Btn2_id"

   android:text="3"

   android:onClick="btn3Clicked"

  />

  <Button

   android:id="@+id/Btnminus_id"   

   android:layout_width="90dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btnplus_id"

   android:layout_toRightOf="@id/Btn3_id"

   android:text="-"

   android:onClick="btnminusClicked"

  

  />

  

  <Button

   android:id="@+id/Btnequal_id"   

   android:layout_width="110dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn1_id"

   android:text="="

   android:onClick="btnequalClicked"

  />

   <Button

   android:id="@+id/Btndivide_id"   

   android:layout_width="90dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btn1_id"

   android:layout_toRightOf="@id/Btnequal_id"

   android:text="/"

   android:onClick="btndivideClicked"

  

  />

   <Button

   android:id="@+id/Btnmulti_id"   

   android:layout_width="90dp"

   android:layout_height="60dp"

   android:layout_below="@id/Btnminus_id"

   android:layout_toRightOf="@id/Btndivide_id"

   android:text="*"

   android:onClick="btnmultiClicked"

  />

</RelativeLayout>



The java file is given below:


package com.arun.calculator;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    
 public String str ="";
 Character op = 'q';
 int i,num,numtemp;
    EditText showResult;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        showResult = (EditText)findViewById(R.id.result_id);
        
        
    }
      public void btn1Clicked(View v){
       insert(1);
       
      }
      
 public void btn2Clicked(View v){
       insert(2);
       
      }
      public void btn3Clicked(View v){
       insert(3);
       
      }
      public void btn4Clicked(View v){
       insert(4);
       
      }
      public void btn5Clicked(View v){
       insert(5);
       
      }
      public void btn6Clicked(View v){
       insert(6);
      }
      public void btn7Clicked(View v){
       insert(7);
       
      }
      public void btn8Clicked(View v){
       insert(8);
       
      }
      public void btn9Clicked(View v){
       insert(9);
       
      }
      public void btnplusClicked(View v){
       perform();
       op = '+';
   
      }
      
 public void btnminusClicked(View v){
    perform();
         op = '-';
   
      }
      public void btndivideClicked(View v){
       perform();
       op = '/';
   
      }
      public void btnmultiClicked(View v){
       perform();
       op = '*';
     
      }
      public void btnequalClicked(View v){
       calculate();
       
      }
      
 public void btnclearClicked(View v){
       reset();
      }
      private void reset() {
  // TODO Auto-generated method stub
   str ="";
   op ='q';
   num = 0;
   numtemp = 0;
   showResult.setText("");
 }
 private void insert(int j) {
    // TODO Auto-generated method stub
       str = str+Integer.toString(j);
       num = Integer.valueOf(str).intValue();
       showResult.setText(str);
       
    
   }
      private void perform() {
    // TODO Auto-generated method stub
    str = "";
    numtemp = num;
   }
      private void calculate() {
    // TODO Auto-generated method stub
    if(op == '+')
     num = numtemp+num;
    else if(op == '-')
     num = numtemp-num;
    else if(op == '/')
     num = numtemp/num;
    else if(op == '*')
     num = numtemp*num;
    showResult.setText(""+num);
   }
    
}



Comments

  1. Thanks you so much. This is the simplest Calculator code even i have seen. thank you so much for this wonderful code. Highly recommended.

    ReplyDelete
  2. could you please let me know how to add (.dot) on this calculater

    ReplyDelete
    Replies
    1. IT IS NOT NECESSARY TO ADD (.) AS A BUTTON .JUST ADD IN EDIT TEXT OF XML- android:inputType=numberDecimal; numberDecimal will accept . values

      Delete
  3. How to solve this error:
    No grammar constraints (DTD or XML schema) detected for the document.
    on line <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    ReplyDelete
    Replies
    1. please add <?xml version="1.0" encoding="utf-8"? this on top of <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android",let me know if the error persists..

      Delete
    2. plz tell me where these methods are called that are defined in the source code?

      Delete
  4. Hi..am getting this problem each time am trying to run the app :

    `main cannot be resolved or is not a field`

    The code with the `main` is as follows :

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    HELP PLZ :(

    ReplyDelete
    Replies
    1. your main.xml file has error , correct it and rebuild the project, give me your emailId i will send you the complete sourcecode

      Delete
    2. This comment has been removed by the author.

      Delete
    3. If you can also send me the complete code... lllach@gmail.com. Thx.

      Delete
    4. HEY MEN U CAN CHANG setContentView(R.layout.main);


      AND ADD setContentView(R.layout.activity_main);

      activity_main IS NAME FOR YOUR ACTIVITY :)

      Delete
    5. plz send me the com plete code.. i am getting same error
      my id is nupurchoudhary12@gmail.com

      Delete
    6. Plz send me the code kamesh0005@gmail.com

      Delete
    7. i am getting the error
      main cannot be resolved or is not a field`

      &
      Error:(19, 49) error: cannot find symbol variable showResult
      please send me the code
      my email id is atulmishra1996@gmail.com

      Delete
    8. please sent the full code of this calculater program

      Delete
    9. please sent the full code of this calculater program

      Delete
  5. Thanks a lot...it worked finally. It was very much helpful for me.

    ReplyDelete
  6. hello ...when I tried to run the program in avd ..it showed the message "Unfortunately Simple calculator has stopped"..need help please

    ReplyDelete
    Replies
    1. give me u r email id i will sent you the complete source code.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. please send da code
      savnish09@gmail.com

      Delete
    4. send me full code , if anyone have ,
      alonesufyan03@gmail.com

      Delete
  7. Really great stuff i find after many tedious programs of calculator.
    really great program.easy to understand

    ReplyDelete
  8. I also get an error in

    setContentView(R.layout.main);

    ReplyDelete
  9. Replies
    1. this program uses int variables so first you should change int to float or double then add '.' button like 1,2,3.. ,
      on clicking add button call insert(),

      Delete
    2. Hi Arun,

      plz send me the complete source code.
      my E-Mail id is jaydeepbldn72@gmail.com

      thank u.....

      Delete
    3. Please send me the source code of adding dot. - benylroger@yahoo.com

      Delete
  10. why it is displaying the message "Unfortunately Simple calculator has stopped"..need help please

    ReplyDelete
    Replies
    1. give me u r email id i will sent yo the complete source code..

      Delete
    2. Hi Arun,

      plz send me the complete source code.
      my E-Mail id is akkichaudhary29@gmail.com

      thank u.....

      Delete
  11. i don't find the number "0" button ... help me out ...

    ReplyDelete
    Replies
    1. sorry,i think i forgot to add button 0 , add it in your code just like other buttons .

      Delete
  12. i got "Unfortunately Simple calculator has stopped" so please help

    ReplyDelete
  13. hey i am getting some problem while running the java code in eclipse IDE ... when i run the code it ask whether u want to run it by java application or java applet, i select the both options one by one but then it says "Selection does not contain a main type" ..
    please help me out

    ReplyDelete
    Replies
    1. please give me your e-mail id, i will send you the complete source cod.

      Delete
  14. This comment has been removed by the author.

    ReplyDelete
  15. please give the full code
    my email id: iambinayakc@gmail.com

    ReplyDelete
  16. can i also have the source code please, jeffreypapali@hotmail.com

    ReplyDelete
  17. helo sir i m nt getting any errors while running but wen i enter a number and aftr dat press any operator(+,-,*,/) then its nt performing ant task,,plz help..:(

    ReplyDelete
  18. hi arun can you also send me the full code.. shibucai11@gmail.com

    thanks!!

    ReplyDelete
  19. Hi! I didn't make an account so can we please keep contact through email ? Mine's asimesoof@gmail.com. My question is how do you have your own colour numpad in the app? For example, like the app: Flib... Also, can you please tell me how to use source codes for converters from websites and include them in the app ??? Thanks in advance & Keep up the good work!!!

    ReplyDelete
  20. Can I have the source code also my email is nlrushin@gmail.com

    ReplyDelete
  21. Tsegay please send the full code to my email tsegay169@gmail.com
    but I admire you for solving that problem!Thanks More !

    ReplyDelete
  22. hi, can i have the source code projot11@gmail.com

    ReplyDelete
  23. Hi !! do i need to change anything in the android manifest?

    ReplyDelete
  24. Email me please for the answer.. Thank you very much I will really appreciate it.
    Here's my email. mikeeconcillado@yahoo.com.ph

    ReplyDelete
  25. Hello! Do you have any source code regarding finding the interest, principal, rate, time in android? If so, kindly email me again. Thank you very much.

    ReplyDelete
  26. hello sir i tried ur code but it gives error when i tap any button on calculator pls help me to figure it out.....apurva16.sharma@gmail.com

    ReplyDelete
  27. Very, very small issue: does not have zero key. Fixing it may be a homework for the reader ;-)

    ReplyDelete
  28. Can you mail me da complete source code?

    Chilieyes@yahoo.com

    ReplyDelete
  29. send me the code to at
    rsrawat1993@gmail.com

    ReplyDelete
  30. You can see the code in complete link in this blog site, http://tobidae.blogspot.com/2013/10/how-to-make-calculator-app-in-eclipse.html it is ingenius

    ReplyDelete
  31. public void btn1Clicked(View v){
    insert(1);

    not working

    ReplyDelete
  32. Thank you very much...very much appreciated.

    ReplyDelete
  33. Hi,

    Can you please explain how do we implement decimal functionality?

    TY

    ReplyDelete
    Replies
    1. same problem i tried so many times does not work

      Delete
  34. This comment has been removed by the author.

    ReplyDelete
  35. can anyone send me the complete code on divya.vy825@gmail,com?

    ReplyDelete
  36. Please somebody send me a complete code of calculator. My email aidas.maleckas@gmail.com

    ReplyDelete
  37. could u please screen shoot the app?

    ReplyDelete
  38. hi
    great and simple to understand
    can you please send the entire sorce code.
    Thanks
    Frank
    email.id-franklin.franz@gmail.com

    ReplyDelete
  39. Hi,
    I'm getting a whole bunch of errors. Please send me the the complete code to miller.seke@gmail.com. Thanks- Seth

    ReplyDelete
  40. same here....send d source code plz....
    blindbat.20@gmail.com

    ReplyDelete
  41. hello ...when I tried to run the program. it showed the message "Unfortunately Simple calculator has stopped"..need help please

    ReplyDelete
  42. my email is imstillstunner@googlemail.com

    ReplyDelete
  43. hello ...when I tried to run the program in avd ..it showed the message "Unfortunately Simple calculator has stopped"..need help please

    ReplyDelete
  44. the application instead of running ,is getting crashed repeatedly
    can u plzz send me the full length code
    my email id: kmnkulkarni79@gmail.com

    ReplyDelete
  45. can u tell me the code to add . button also to calculate float value.

    ReplyDelete
  46. Hy.. this application is running well.. highly recommended..
    but how about sin con tan?? can we resolve it? if we want to calculate sin 90?? thankss admin

    ReplyDelete
  47. Great! Thank you for the author of this code...! GBY!

    ReplyDelete
  48. This comment has been removed by the author.

    ReplyDelete
  49. Everything is better but mouse click event handling is the best man!

    ReplyDelete
  50. Thanks a lot! Icould install and run on my nevono as well as my tab karbonn 1 !!

    ReplyDelete
  51. Thanks for sharing! But there's runtime errors. Pls send me the complete code. email: doub1ea1006@gmail.com. Thanks alot!

    ReplyDelete
  52. Hello, this works amazing. But what I want to do now is to show the full equation in the edittext. For example, I want to show 8 + 8 , then when I click the = sign, thats when the results change to 16. I just want to show the whole equation. How can I do that with your code?

    ReplyDelete
  53. Hi..am getting this problem each time am trying to run the app :

    `main cannot be resolved or is not a field`

    The code with the `main` is as follows :

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    HELP PLZ :(
    my emailid is adqureshi@gmail.com

    ReplyDelete
  54. This comment has been removed by the author.

    ReplyDelete
  55. Can you send me the full source code plz,
    juventus199548@gmail.com

    thx.

    ReplyDelete
  56. Hi can you pls send me the source code at saurabh1832@gmail.com

    ReplyDelete
  57. plz send me source code at sardartashaf@gmail.com

    ReplyDelete
  58. This comment has been removed by the author.

    ReplyDelete
  59. hello, could you please send me full source code, encountering two errors in main.java file

    gaetano.1993@yahoo.com

    ReplyDelete
    Replies
    1. import android.app.Activity;
      import android.os.Bundle;
      import android.view.View;
      import android.widget.EditText;

      public class MainActivity extends Activity {

      public String str = "";
      Character op = 'p';
      int i, num, numtemp;
      EditText showResult;


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

      showResult = (EditText) findViewById(R.id.result_id);

      }

      public void btn1Clicked(View v) {
      insert(1);

      }

      public void btn2Clicked(View v) {
      insert(2);

      }

      public void btn3Clicked(View v) {
      insert(3);

      }

      public void btn4Clicked(View v) {
      insert(4);

      }

      public void btn5Clicked(View v) {
      insert(5);

      }

      public void btn6Clicked(View v) {
      insert(6);
      }

      public void btn7Clicked(View v) {
      insert(7);

      }

      public void btn8Clicked(View v) {
      insert(8);

      }

      public void btn9Clicked(View v) {
      insert(9);

      }

      public void btnplusClicked(View v) {
      perform();
      op = '+';

      }

      public void btnminusClicked(View v) {
      perform();
      op = '-';

      }

      public void btndivideClicked(View v) {
      perform();
      op = '/';

      }

      public void btnmultiClicked(View v) {
      perform();
      op = '*';

      }

      public void btnequalClicked(View v) {
      calculate();

      }

      public void btnclearClicked(View v) {
      reset();
      }

      private void reset() {
      // TODO Auto-generated method stub
      str = "";
      op = 'p';
      num = 0;
      numtemp = 0;
      showResult.setText("");
      }

      private void insert(int j) {
      // TODO Auto-generated method stub
      str = str + Integer.toString(j);
      num = Integer.valueOf(str).intValue();
      showResult.setText(str);

      }

      private void perform() {
      // TODO Auto-generated method stub
      str = "";
      numtemp = num;
      }

      private void calculate() {
      // TODO Auto-generated method stub
      if (op == '+')
      num = numtemp + num;
      else if (op == '-')
      num = numtemp - num;
      else if (op == '/')
      num = numtemp / num;
      else if (op == '*')
      num = numtemp * num;
      showResult.setText("" + num);
      }
      }

      Delete
  60. This comment has been removed by the author.

    ReplyDelete
  61. Sir,,please send me the source code,,,i got "unfortunately....." problem,,,here is my id
    pasu.cs@gmail.com

    ReplyDelete
  62. sir i really need your source code in the simple calculator.. philipjanbaruis@gmail.com

    ReplyDelete
  63. have u source code for scientific calculator ?

    ReplyDelete
  64. I am not getting any errors .... but when i run the program, the layout is not being displayed on the screen ... please help ..!!

    ReplyDelete
  65. hy ive tried ur code but i cant run it .. it says "Your project contains error(s) ..
    sir can u send me the full code please .
    heres my email christoedge@gmail.com

    ReplyDelete
  66. can you plz tell me where you called the methods that are defined in your source code?

    ReplyDelete
    Replies
    1. 1) insert() method is called when we click a number 1 to 9
      public void btn3Clicked(View v){
      insert(3);

      }
      2) perform method is called when we click +,-,/,*

      public void btnminusClicked(View v){
      perform();
      op = '-';

      }
      3) calculate method is called when we click " = "

      public void btnequalClicked(View v){
      calculate();

      }

      Delete
    2. hello Arun
      I added zero and double zero button in my app but on click of double zero button its displaying only "0" and I also want to add "." in my calculator please help me out. Ty

      Delete
  67. The calculator doesn't display the signs +,-,*,/. Why is that? Is there any extra code to be written for that signs to display?

    ReplyDelete
    Replies
    1. yes you can code some lines extra for showing these charcters

      Delete
  68. Android Development Tutorial: Creating a Simple Basic Calculator : https://www.youtube.com/watch?v=8gE5pQNK3Wc

    ReplyDelete
  69. thanks its Work if u set this Variable to to

    float i,num,numtemp; instead of int you can then find the Calculation in Decimal other wise this code does not show the result of 1/2 as well only integers values are returned thanks it is working and nice effort

    ReplyDelete
  70. Your comment is awaiting moderation.
    good information but difficult for beginners i have found it simple on http://infoocode.blogspot.com/2015/11/Simple-android-calculator-code.html

    ReplyDelete
  71. can you give the full source code with "." and "%" ....
    my id is : multaniidrish39@yahoo.com

    ReplyDelete
  72. Please send complete code please temifadstellah50@gmail

    ReplyDelete
  73. please send the total code with adding DOT My Mail ID : pdvsnarayana@gmail.com

    ReplyDelete
  74. plz send me the total code to complete this
    my id is irfanqasim750@gmail.com

    ReplyDelete
  75. hello Arun
    I added zero and double zero button in my app but on click of double zero button its displaying only "0" and I also want to add "." in my calculator please help me out my mail id is: riteshs027@gmail.com. Ty

    ReplyDelete
  76. Hey Arun,

    I'm trying to run your app but keep getting two errors.

    One of them says: error: cannot find symbol variable main

    I'm wondering if you can help me out with this.

    Thanks

    Email is ad.litterateur@gmail.com

    ReplyDelete
  77. Hi
    you have build an excellent cal just one error i am receiving is that main is not defined in R.java
    how to solve that
    Kind Regards
    Aditya

    ReplyDelete
  78. plz send me the complete code.. i am getting same error
    my id is rizwansheikh464@gmail.com

    ReplyDelete
  79. Its a good tutorial to get the basics clear you can modify the codes and add new features later on, I was able to build my own Calculator app with history save support..

    App Link : https://goo.gl/oqhLK2

    ReplyDelete
  80. in the function perform()
    Why you have set numtemp=num?
    what does it will do?

    ReplyDelete
  81. what's the purpose of insert function ???

    ReplyDelete
  82. I am run it on Ubuntu 14.
    Can you please resolve my following error??
    [MainActivity] Unable to resolve target 'android-8'

    ReplyDelete
  83. Can u please send me the source code ?
    My email id is --- rajnishkumar307@gmail.com
    i will be thankful to u

    ReplyDelete
  84. kindly send me this code on my email
    knvlsh88@gmail.com is my email

    ReplyDelete

Post a Comment

Popular posts

Android Sqlite and ListView Example

This is simple application which insert data into Sqlite database --and shows the data  from the database in a ListView ListView is not used in android Anymore . We use RecyclerView and CardView   in Android RecyclerView Demo is available on the following link http://androidtuts4u.blogspot.in/2017/04/android-recyclerview-example.html RecyclerView with CardView Demo is available on the following link http://androidtuts4u.blogspot.in/2017/09/android-card-view-example.html This  is the first Activity of application which shows data from database in listview. Register here buton will start a Registration Activity. Submit button will add data to database and show it in the ListView of MainActivity. Update can be performed by clicking ListView items.     you can download the source code of this project from  google drive   https://drive.google.com/folderview?id=0BySLpWhqmbbdS0dtT1R2TXdBWEE&usp=sharing click on the above link ->sign into  your  google acc

Android Card View And RecyclerView Example

CardView Cardview lets you show information inside cards that have consistent look across the platform . CardView is introduced with material design through support v7 library. CardView extends frame layout and It can have shadows and round corners.     Cards can be used as independent views that serves as an entry point to more detailed information. CardView can also  be used with RecyclerView to display cards as list. In this example we are using Cardview with Recyclerview to show data as list of cards. Our Demo application contains vertical list of cards . Each card contain Movie name, movie poster and director name. screenshot of demo app 1. CardView and RecyclerView are supportV7 library widget . so we need to add dependency for both in app level build.gradle file . which is in the app folder compile 'com.android.support:cardview-v7:26.+' compile 'com.android.support:recyclerview-v7:26.+' build.gradle file is apply plugin: 'com.android.applicat

Android RecyclerView Example

RecyclerView RecyclerView is the advanced version of Listview . It has more flexibility than ListView . RecyclerView is Compatible with Api level 7 onward . We need an adpater class and layout manager for creating Recyclerview.  RecyclerView has 3 built in layout managers LinearlayoutManager - this shows items in vertical or horizontal list GridLayoutManger - this shows item in a grid StaggeredGridLayout Manager - this shows item in a staggered grid we can also create custom layout mangers by extending RecyclerView.LayoutManager class RecyclerView does not have a divider to separate ts iitems . if we want divider we need to extend ItemDecoration class to display the divider RecyclerView also does not have an onItemClickListener for onClick events so we need a class extending RecyclerView.OnItemTouchListener for onclick events or we can use onlick listener in our adapter class we use LinearLayoutManager and a custom Adapter class in this example . This Demo app does no