Android RecyclerView with EditText Example

Android RecyclerView with EditText example tutorial guide you to add edittext in the every cell or child of the recyclerview.

I have used a Model class to maintain proper data and the value of edittext in the recyclerview.

You will also learn how to fetch value of the EditText of all the rows. We will pass these values to the Next Activity.

Most common problems regarding this topic are

  1. Value of edittext get change when scrolling
  2. Edittext loses content on scroll in recyclerview

  3. Edittext loses focus in recyclerview

This tutorial will solve all the above problems in this Android RecyclerView with EditText Example.

We will use the TextWatcher class to control the changes of the edittext.

Check out the output of Android RecyclerView With Edittext tutorial.

Also Read,

Try Birthday App

We have developed below app which allows you to wish a happy birthday with name and photo on birthday cake to your friend.

Visit app here :

1. Make RecyclerView item

Create a resource file and give it a name rv_item.xml

This file shows how a single cell of recyclerview will be look like.

2. Updating build.gradle(Module:app)

Add below lines in build.gradle(Module:app)

Above lines will add support for recyclerview and cardview. By default, it is not supported in android studio project.

Full code

3. Preparing Model Class

Make a new java class named

  • In our recyclerview, only the value of edittext is changing so we need to maintain it with model class.
  • Above class is that model who holds the getter and setter methods for the value edittext.

4. Adapter class

Create a new class and it’s name should be

First of all, consider the below code

    • First line will create the object of the LayoutInflater class.
    • Second will create one Arraylist with objects of the EditModel class.
    • Then I have created a constructor of the adapter class.
    • Compiler will get a context and arraylist from the parameter of this constructor.

Now look at the below code

  • In the above code, we are setting the value of the EditText.
  • Here, we are using that Arraylist with the objects of the EditModel class.
  • Main logic is present in adapter class. We will change and store the value of edittexts in this.
    Look at the following code

  • When user changes the value of edittext, above lines will be excuted.
  • When text is being changed, we will store the new value of edittext in arraylist.
  • Arraylist is made public in the adapter class. This arraylist can be used anywhere in the whole application.

5. Making next activity

Make a new activity with name

Add below source code in this class

  • In this next activity, we will show all the values of edittexts.
  • Here, we have used that public arraylist to fetch the values.

Updating activity_next.xml

Copy below code

6. Changing

Update class with following source code

Pay attention at the below code

  • Above line is creating a data structure. Compiler will use populateList() method for this purpose.

Following is the code for populateList() method.

  • In this method, compiler will run one for loop for seven times.
  • In the each iteration, it will create one object of the EditModel class. Then it will set the value of the edittext.

Read the following code

  • Compiler will run the above code when the user clicks on the button.
  • It will open a Next Activity via above code snippet.

Add below code in activity_main.xml

I have taken one button and one recyclerview in the main layout.

Thus, edittext is not losing focus neither it’s value is changed on scroll.

We always try to solve the hard and complex real world problems regarding android development.

Keep visiting other tutorials for other wonderful logic and time saving techniques.

So, it was all for the tutorial.

If you have any questions regarding logic of adapter class or anything else, then feel free to ask in comment section.

Download Source Code For Android RecyclerView With EditText Tutorial

[sociallocker]Recyclerview_Edittext [/sociallocker]

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

24 Responses

  1. Ammi Singh says:

    thanks you sir for this post

  2. manjoor alam says:

    your example is not working in my project

  3. Subhash Salian says:

    I tried working on your example with multiple edittextboxes, but somehow it didn’t work. The data is getting displayed correctly, but I am not able to input any characters into the edittextboxes.

  4. Subhash Salian says:

    hi Hardik,

    The post is very good and you have explained it very well. I am trying with multiple edittextboxes using your example, however i find that the edittextboxes are not receiving focus. I have implemented textwatcher for each edittextboxes in the Viewholder class. Please share your inputs.



    • Hardik Parsania says:

      I guess you are trying to add two or more edittexts in one single row.
      Are you able to input text in one single edittext among all or non of edittext is receiving focus?

      • ahmad t says:

        i’m right now facing this problem.
        i need to add tow edit texts in one row how can do that.

        • Hardik Parsania says:

          Add edittext in row_layout.xml
          Add edittext in model class same as we have addedfirst edittext.
          Then also add code in adapter class for your second edittext same as i have added for first edittext.

  5. Shreya Garg says:

    i tried your way it didnt worked for me….can u pls help

  6. davod_basiri says:

    hi sir i tried your way but have one error
    void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)’ on a null object reference

    • Hardik Parsania says:

      I have not set any onclick method for textview in this example. You are getting this error because you have not initialize your textview.

      I think you are integrating this project directly in your existing project.

      Make separate project and follow this example. Once you learn it completely then try to integrate it with your existing project.

  7. davod_basiri says:

    tried your way it didnt worked
    ‘void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)’ on a null object reference

  8. Omar says:

    I know this is incredibly late but I was curious how are you able to call “setEditTextValue” without instantiating the model class.I’m doing something very similar instead of an array list I’m getting my data from an Sqlite database. I would really appreciate any feedback!

    • Hardik Parsania says:

      I have used setEditTextValue in adapter class and in Main Activity. Which setEditTextValue you are taiking about?

  9. sumitranjan says:

    hi i want to get textview value from a row of recyclerview and show on the edittext of another activity can u plese help me

  10. vanami says:

    hi, good tutorial but is there a way to keep the focus in an edittext even if that edittext is no longer visible because it was scrolled out of view? Or is this even possible with a RecyclerView?

  11. Ahmad says:

    Awesome man 🙂 You rocked

  12. Richard Mubalama says:

    This tutorial is awesome , it really help me alot thank you sir

  13. Raj says:

    Not working bro….
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.get(

Leave a Reply

Your email address will not be published. Required fields are marked *