kirtan403
kirtan403

Reputation: 7421

Issues with small RecyclerView with EditTexts and Checkbox

I have a small list of almost 10 items (and this will not be greater than 20 in any case). It will not be changed after activity is created.

My Current Setup:

Problems solved:

Another Problem:

Now, as data change of EditText-1 changes values for all other items of RecyclerView, I am calling notifyDatasetChanged() to reflect the changes after doing calculations. But this causes the EditText to loose focus. And it intends as all the views are recreated after notifyDatasetChanged. Even stable ids are also not useful in this situation. (There is bug related this issue: https://code.google.com/p/android/issues/detail?id=204277). The value is not even reflects and EditText looses it focus.

What can I do?:

Upvotes: 1

Views: 469

Answers (2)

hArsh
hArsh

Reputation: 111

The solution is simple, don't call notifyDatasetChanged() when your data is changing instead call notifyItemChanged() or notifyItemRangeChanged() which will update only that view which has the changes and your focus will remain as it was.

Upvotes: 0

Reaz Murshed
Reaz Murshed

Reputation: 24211

Lets take an array of objects to save the statuses of your EditText along with the values to be populated in your list. For example each of your items in the list might look like this class.

public class ListItemCustom {

    // Add some extra parameters to handle the state of the EditTexts
    public String textOfEditText1;
    public String textOfEditText2;
    public boolean focusEditText1;
    public boolean focusEditText2;

    // Contains original values of your list item
    public OriginalListItem mOriginalListItem;
}

Now take an Array or ArrayList of ListItemCustom custom and populate your items there inside onCreate. Then pass this list in your adapter and then handle the EditText and the values accordingly.

Hope this helps.

Upvotes: 0

Related Questions