In my bindRow method of my RecyclerView adapter I am checking to see if an EditText has been modified such that its value falls below 100. If so, I change the color of the text to red.
However the text does not update immediately unless I rotate the screen.
How do I get it to change the color immediately?
From my experience, this isn't the place where I would be doing this. I have had a similar concern where the ViewHolders in my Adapter weren't accurate - and then rotating the screen 'fixed' it.
My solution involved updating my Adapter's data List<> and then calling swapAdapter(...)
Related
I have 2 recycleviews and both of them have a number of icons. I also have a list that contains a number, which is the number that represents which icon has a background that shows it has been clicked.
Now, the problem is that I only want one icon marked, with this I mean 1 item in total of those 2 recyclewviews. The way I've tried to do this is having a json that saves a number that determines which recycleview should have a marked item, if it doesn't have the number of the recycleview, then the background is the normal one, that way only one recycleview has a marked item.
The problem is that for that to work I need to call the method Notifydataserchanged() on the other adapter so the marked background dissappears, and the easiest way of doing that is putting the other adapter on the constructor. The problem with this is that only works for one, because since the other is declared before you can't construct it with the adapter that comes after it.
I've seen way of doing it with listeners/interfaces made in the activity and then
moved to the adapter itself so you can just call those methods, but it hasn't worked for me.
Any ideas? Thanks
I would like to know some codes on how to restore the Color of ListView after orientation changed. From landscape to potrait and vice versa. Thank you.
I m not sure i understood what you want to achive but if i get it right you have a ListView and you want to color every item with different color.
There are several way of doing this, one and the simplest is to handle the configuration change by yourself by defing the Activity with this:
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
your Activity won't be recreated on all this events and it will just resize your view without loosing the state. Be carefull this has lots of down sides depending on what you are doing in your Activity/Fragment.
An other solution is to keep track of the state of every ListView item by yourself, so, for instance make an int array and save there the color of all your list view elements and use it to color the view in your adatper getView() call.
My problem is on two fronts.
First issue: Scrolling amnesia
I have a ListView with spinners and edit texts. It acquires it's data from webservice. The problem is when I write up a value on the EditText or select something for the spinners and scroll them out of view. When I come back the fields are empty and the spinners are again in their default selection.
Attempted solution
I have tried resolving the issue by setting ScrollingCacheEnabled programmatic and within the AXML file to both true and false just to see if that is an issue. It seems not to have any kind of an effect.
Second issue: Focus Loss
When I touch the EditText within this same ListView I get the keyboard to appear but I loose the focus on the field and it needs to get touched again to get focus and it allows me to be written.
Attempted solution
I fiddled with setting the fields focusable, Focusavle in toucmode, touchable and whatnot but came out empty handed.
Honestly I am quite new to android and to programming on this level as well but I tried my best on this. I might have just missed something due to lack of knowledge or it's just something somebody with more experience could tackle and solve.
The second issue isn't that bad for now (still after filling out quite a number of fields it does get tiring to set it twice...) but the scrolling issue is a must.
I think you problem relates to that you forget to update the items in the Adapters when you alter the Views containing them. So you need to wire up the events from the Views to update the items.
Why? If you look carefully at your Adapter for you ListView you populate the convertView with the values of GetItem(position). So if that item does not reflect the changes you have made to the View you are bound to get the initial values of that item.
So what you need to do is to hook up SpinnerValue.ItemSelected and all the other Views which can be altered events, so that the items in the Adapter get their values updated. Remember to only add event handlers when you first create the View. So that is when convertView is null.
Also consider changing the lines:
if (SpinnerValue.Adapter.Count.Equals(2))
{
SpinnerValue.SetSelection(1);
}
To be based on the items in the Adapter rather than setting it to 1 every time.
You focus problem is based in that ListView is not really made for having Views inside of it wanting the focus. Try setting the ListView DecendantFocusability when you instantiate it to DescendantFocusability.AfterDescendants like so:
lstPrevzem.DescendantFocusability = DescendantFocusability.AfterDescendants;
I resolved the issue by replacing the listview with LinearLayout and pinning the adapter to it. The "fixed" code is available on pastebin.
Fixed code:
http://pastebin.com/vn3SPrFz
This is my first post on stackoverflow. I use this one some times when I have a problem and find a solution every time. But today is different. Have a non-solved problem :
I have on listview and I want apply a magnetic effect on this. To make this, I use scrollBy one by one pixel with Thread to move listview position. Visually, it's perfect, listview move good. But when user want scroll again, listview come back to his previous position (just before scrollBy) before scroll normally with user finger.
I've tried some tests, for exemple I display v.getTop() (v is on view item in listview) value BEFORE my scrollBy and AFTER. Values are same, but visually are really different because list are moved. Also visually, you can see a little artefact : this divider is ON listview item. It's means that visually, listview is good, but programatically isn't good... while scrollBy make invalidate estate.
Anyone have an idea or a solution ?
Thnak you for your help.
PS : Sorry for my english, i'm french. Thank you again.
Use getScrollY() to find the current position and then set that position after it gets reset.
I am using a ListActivity to display an iconified list (using a custom implementation of BaseAdapter). It does not reload data properly. When I change the contents of the adapter and notify the list, it appears that the old data draws on top of the new data, until a scroll event happens. The old rows draw on top of the new rows, but the old rows disappear when I start scrolling.
However if I set the ListActivity style to Theme.Dialog, it refreshes fine. (presumably because when in dialog, the activity resizes each time the list contents changes, which forces a redraw of the whole view hiearchy?)
Any ideas how to make this work in my fullscreen activity?
Thanks.
Did you try to call invalidate() on your listView?
Here are some function you could try:
invalidate()
requestLayout()
forceLayout()
You could even do that, when your thing is iconified( I don't exactly what you mean by that). You could set the adapter of the view to null or an empty adapter. Something empty just enough to not make your activity crash. Then when you want to display your ListView just set the adapter back to it.
That could be linked to drawing cache but it would be good if you could give us some more information.
Oddly enough, if I set a background color, everything refreshes properly. Without the background color, I get the refresh issues I described in the original post.