samedi 23 juillet 2016

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:

  • I am using a RecyclerView for the list.
  • I have a Checkbox and 2 EditText (say 1 and 2) in each list item.
  • I do some calculations based on if checkbox checked and the value of EditText-1 and populate the new values to another EditText-2.
  • On some cases user edits the Value of EditText-2 and calculations happen again and it will be populated in all other places including EditText-1 of for all the items.

Problems solved:

  • However, in this situation I was facing issues with the TextWatcher called multiple times. I solved it with this: http://ift.tt/2a4wZvW

  • Changing Checkbox values changing some random other checkboxes. Solved it using this: http://ift.tt/2a5tqZS

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: http://ift.tt/2a4vo9P). The value is not even reflects and EditText looses it focus.

What can I do?:

  • Is there any workaround? I am seeing strange changes in items values after setting stable ids.
  • As the Items are fixed and no items are added and removed after onCreate, Using a scroll view with the container and adding items by manually inflating views in loop (and updating also will be ease, I think) will make my life a little easier?



Aucun commentaire:

Enregistrer un commentaire