Reputation: 7421
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:
RecyclerView
for the list. Checkbox
and 2 EditText
(say 1 and 2) in each list item. Problems solved:
However, in this situation I was facing issues with the TextWatcher called multiple times. I solved it with this: https://stackoverflow.com/a/31860393/1820644
Changing Checkbox values changing some random other checkboxes. Solved it using this: https://stackoverflow.com/a/38549047/1820644
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
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
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