Jan 8 | 7:20 PM |
Mark M. | has entered the room |
Jan 8 | 7:25 PM |
Mark M. | turned on guest access |
Jan 8 | 7:55 PM |
Tad F. | has entered the room |
Mark M. |
hello, Tad!
|
Mark M. |
how can I help you today?
|
Tad F. |
Hi Mark!
|
Tad F. |
I've got a nagging issue with a RecyclerView - I am attempting to dynamically bind it and show/hide widgets in the item layout based on data in the source.
|
Tad F. |
What I'm seeing is that the holder being reused seemingly confuses the UI
|
Mark M. |
"confuses the UI"?
|
Tad F. |
I've set hasStableIDs, and also overridden getItemId() and getItemViewType()
|
Tad F. |
per SO posts
|
Tad F. |
but I'm still seeing it
|
Mark M. |
what exactly is "it"?
|
Tad F. |
Yeah - so what I mean is - some elements of the RecyclerView should have an icon that means the data in that item has a certain value, others dont have that value so the icon should not be shown.
|
Tad F. |
What I'm seeing is that initially all looks good
|
Tad F. |
Then as I scroll up and down, the icon appears in entries it shouldn't, and vice-versa
|
Jan 8 | 8:00 PM |
Mark M. |
are you always positively setting the visibility? IOW, are you guaranteed that in your bind function, you are always setting the visibility to some value, regardless of the data being bound?
|
Tad F. |
Yes
|
Mark M. |
or, are you saying "if the data is X, make the icon visible", and relying on some default for the data-is-not-X case?
|
Tad F. |
Not relying on a default.
|
Tad F. |
View paste
|
Tad F. |
That's the last block of code in my onBind
|
Mark M. |
is the icon the only thing that is not working? or are other elements in the views also messed up?
|
Tad F. |
Just the icon
|
Mark M. |
is getAbsolutePathToAudio() stable? IOW, will its data change for a given Media object?
|
Tad F. |
Well, it could be null or an empty string, per the test.
|
Mark M. |
but will the value change, for a specific instance of Media? IOW, is it mutable?
|
Tad F. |
But for a given object in the recyclerview it is stable at the time the view is shown.
|
Tad F. |
No - if the user clicks a button - new screen that allows them to record audio, and that path is stored. But on return I'm doing a notifyDataSetChange
|
Jan 8 | 8:05 PM |
Tad F. |
What I'm seeing is just scrolling the screen up and back, icon appears/disappears on a particular item.
|
Tad F. |
Like moving it up just past the halfway point on the screen in one example triggered it.
|
Mark M. |
wait... the icon changes while the view was still visible? not when the view scrolled off the screen and scrolled back?
|
Tad F. |
Corect
|
Tad F. |
correct
|
Tad F. |
I'm assuming that holder is getting reused under the covers somehow...?
|
Mark M. |
is anything other than your onBind() function affecting these widgets?
|
Tad F. |
NO
|
Tad F. |
No
|
Tad F. |
Not at the time I am scrolling around anyway.
|
Tad F. |
I do have a sort feature implemented.
|
Tad F. |
But again - you change the sorted by, and I notifyDataSetChange
|
Mark M. |
is the value of the item variable from your code snippet passed into onBind()? or are you holding onto it in a field?
|
Tad F. |
The value is being held in a field.
|
Mark M. |
that's not good for a viewholder
|
Mark M. |
they're designed to be recycled
|
Tad F. |
OK maybe that's it.
|
Tad F. |
Base class onBind:
|
Tad F. |
View paste
(23 more lines)
|
Mark M. |
I'd try to get rid of mItem (which I presume is your field)
|
Jan 8 | 8:10 PM |
Tad F. |
Hmmmm.....ok I'll look into that.
|
Tad F. |
I assumed the lifetime of the holder until bindItem() was called again was ok.
|
Mark M. |
let's just say it makes me nervous
|
Tad F. |
That's a pretty big limitation now that I think about it....like the checkbox I'm using to indicate multi-select.
|
Mark M. |
having mutable widgets in a RecyclerView itself is a pain
|
Tad F. |
I set that in onbind based on an array where I'm keeping track of user selection.
|
Tad F. |
Maybe what I need to do is actually just not keep mItem, but I can keep references to the other fields I bind?
|
Tad F. |
That seems doable.
|
Mark M. |
I'm not certain what "the other fields I bind" means in this context, so I can't comment on it
|
Mark M. |
a viewholder can have references to the widgets in the view that it manages
|
Tad F. |
That's what I mean
|
Mark M. |
that's fine -- it's references to model objects that make me nervous
|
Tad F. |
Here is an issue though, if I don't keep a reference to that item - I have a checkbox that should show checked if the user has selected the item or unchecked if not.
|
Tad F. |
Right now, in the click listener for the checkbox I need to either set or unset the ID of the item associated with that holder at the time the user clicks the checkbox.
|
Tad F. |
If I don't keep mItem in order to get the id at such time the user clicks the checkbox, how do I know what to set/unset?
|
Mark M. |
if your list was stable, I'd say use the position index, but it sounds like your list is not stable
|
Tad F. |
I'd have to set the click listener each time onBind is called?
|
Tad F. |
Right now I do this in the constructor of the holder
|
Jan 8 | 8:15 PM |
Mark M. |
that would be another option, capturing the ID in the listener object
|
Tad F. |
View paste
(15 more lines)
|
Mark M. |
if you want to try to keep mItem around, that's your call -- but then you are going to need to log the heck out of your binding logic and figure out who is calling it, when, and for what items
|
Tad F. |
I get you.
|
Tad F. |
I realize looking at this code that I'm passing 'mItem' fro the bindItem call out of my base class. Maybe I will try just passing the item that is the subject of the bindItem instead.
|
Mark M. |
getting back to the root problem... in your original code snippet, you used all three visibility values
|
Tad F. |
Not sure how I'm going to solve the issue with the checkbox listener though...
|
Tad F. |
Yes
|
Mark M. |
obviously, for cases where the icon is visible, you used VISIBLE
|
Mark M. |
for the cases where the icon is missing when you expect it, can you tell by eyeball if it is INVISIBLE or GONE?
|
Tad F. |
The reason is that in ACTION_MODE, I want voice-over icon (and there is a settings icon also that is always there), both GONE.
|
Tad F. |
The checkbox should be the only one there, taking up real estate
|
Tad F. |
Otherwise, I shift between visible/invisible to keep the dimensions stable between those two other icons (settings and voice-over)
|
Tad F. |
That's all working ok.
|
Tad F. |
May look a little strange, but it is correct.
|
Mark M. |
that's fine -- I'm just trying to figure out if all three states are in flux, or just two
|
Tad F. |
The checkbox is visible or GONE.
|
Tad F. |
When the checkbox is visible, the other two icons are GON
|
Tad F. |
When the checkbox is gone, the other two icons are either both visible, or the settings is visible and the voice-over is invisible
|
Jan 8 | 8:20 PM |
Tad F. |
That way, I don't have some entries with a much larger settings icon than others that are splitting real estate between settings icon and voice-over icon
|
Mark M. |
except that the root problem is that this isn't working, and you are seeing or not seeing the icon at times when you expect the opposite
|
Mark M. |
right?
|
Tad F. |
Between checkbox and the other two icons, it is always working.
|
Tad F. |
The problem is when checkbox is GONE, the other two icons aren't always showing correctly.
|
Tad F. |
Gotta jump. Thanks for your input.
|
Tad F. |
Happy New Year1
|
Tad F. |
!
|
Tad F. | has left the room |