last day (15 days later) » 

20:52
0
A: ListView Adapter Async Manipulation

113408 This works if I just set the color from the database and skip the async bit. But when I use async it doesn't work. This happens because your AsyncTask doesn't work on the UIThread and therefore when the result is back it doesn't redraw your items. To do so you need to notify the adapter th...

I actually can't access my recyclerView I only have access to the view objects. I can't update the adapter nor the layoutManager.
and if I have over 100 items, Its gonna call that piece of code 100 times, I don't see a way my code isn't called on UIThread either since it's called on onPostExecute?
@SamzSakerz the purpose of using AsyncTask as you mentioned is to not block your UI while loading the stuff from cache/DB. So when the result is back onCreateViewHolder is not called again and therefore your color doesn't get applied.
Well my issue is I can't access the recylerView ref, Since the workspace I am working on is limited, I only have access to the getView on the adapter
Oops, I actually made a mistake on the question I am not actually using a recylerview I forgot I switched my code to github.com/ksoichiro/Android-ObservableScrollView/blob/maste‌​r/…, So Its actually a ListVIew. I will update the question
I updated the question but yeah, I can't access the ListView reference, Since I don't want to pass it to my adapter.
@SamzSakerz have you tried myAdapter.notifyDataSetChanged(); on the setBackgroundColor ?
No I did not, Since I am only passing the view. I don't think I am allowed to pass the adapter.
20:52
Are you able to share the code on how you setup the adapter and how you call setBackgroundColor ? if so please update the question
I am afraid I can't show you how I setup the adapter. but basically this is what I do for the setBackgroundColor part. I just call it on my custom layout on the getView method.
Updated the question, showing how I call the setBackground
I am gonna try to pass this to my setBackground method as BaseAdapter and try to call notifyDatasetChanged inside onPostExecute and let you know how it goes.
Hi, I tried what you suggested just now, and it didnt work.
Updated post. .
Hi
Hey, the problem is for sure coming from the re-rendering of the items
```
public final View getView(int i, View view, ViewGroup viewGroup){\
...
view = inflate(R.layout.my_view, viewGroup, false);
setBackground(view);
...
}
```
This is why I thought setBackground is part of your adapter
Oh, It's in an outside class. I just showed an example of how its called
I think whats happening here is the onPostExecute is getting called after my adapter returns the view.
But I am not sure how to combat that
notifyDataSetChanged will trigger the rendering of the items, you just need to make sure you call it on the right reference of your adapter
Wait, I think I know where the problem is coming from :O
Look at the getString method in my code
                String k = cursor.getString(cursor.getColumnIndex(ThemeDatabaseHelper.COLUMN_NAME_TITLE));
                String value = cursor.getString(cursor.getColumnIndex(ThemeDatabaseHelper.COLUMN_NAME_SUBTITLE));
                if (k.equals(key)) {
                    cursor.close();
                    if (database.isOpen()) database.close();
                    ThemeDatabaseCache.lruCache.put(key, defaultValue);
                    return value;
                }
I am caching the default value and not the actual value!
this might be the error.
I will change this and see if it fixes it
That actually fixed it!
That was the error all along
21:03
We just assumed it was elsewhere xD
Well you can update your answer with that ^ and also keep the notify part and I will accept and reward the bounty
Do you happen to know a better way to get the value from database? I think looping the keys is slowing it a fair bit
are you using just few key values (100-1000)? or the number might exponentially grow ?
I would just warm-up the cache before hand and not have to query the DB when I need the resources
I am making a theme picker for my app
the user can pick the color of all the views as they wish and share it on another app that I will create.
So yes it will depand
but the number is well above 150 at this moment.
Just removed the datasetChange code, It works without it so no need to include it on your answer if you dont want to.
Glad that it worked, notifyDataSetChanged might help others
ight
Looks like I cant award bounty before 24 hours, I accepted it for now

last day (15 days later) »