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.

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

We will solve all 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.

Download Source Code For Android RecyclerView With EditText Tutorial

Also Read,

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 EditModel.java

4. Adapter class

Create a new class and it’s name should be CustomAdapter.java

Main logic is present in adapter class. We will change and store the value of edittexts in this.

Look at 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 NextActivity.java

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 MainActivity.java

Update MainActivity.java class with following source code

Add below code in activity_main.xml

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.

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...

14 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.

    Thanks,

    Subhash

    • 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

Leave a Reply

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