Featured post
android - Strange ArrayAdapter behaviour -
i'm writing application android-based tablets. while have come far in development, there 1 bug don't understand , can't rid of. have gridview custom arrayadapter, contains downloadable items in it. each item in grid clickable relative layout, looks this:
<relativelayout> <framelayout /> <textview /> <textview /> <progressbar /> </relativelayout>
when item clicked, app try find on sd-card , show it. if fails, start downloading in it's own thread. file-downloading method standard, except 2 things things - has, said, it's own thread , updates progress-bar after downloading each data-chunk (which, @ moment, 2048 bytes):
while ((n = in.read(b,0,chunksize)) >= 0) { out.write(b,0,n); if (handler != null && progressbar != null) { /* update progressbar:*/ currentbytes += n; final int nbytes = currentbytes; handler.post(new runnable() { public void run() { progressbar.setprogress(nbytes); } }); } }
this works well. here's how looks in real world (after clicking on 3rd icon; these items placeholders, downloaded files real):
[i couldn't post image (not enough rep), here's link]
http://i52.tinypic.com/20zb8jq.png
in same time can start second download , still work perfectly. can add elements @ end , work too. there slight problem, however. whenever use search button, starts new activity, , go activity, same gridview this:
[i couldn't post image , 1 hyperlink (not enough rep), here's link space]
http:// i54.tinypic.com/16kqgxg.png
it's still downloading right element, shows wrong progressbar. magazine still shown after downloading completes. unwanted effect items, downloading , progress bars, set clickable (i disable before starting downloading). here code (a bit shortened, doesn't matter) updating adapter:
list<magazine> newlist = cm.getmymags(); // returns list of current magazines list<magazine> oldlist = cachedadapter.mags; // use list.toarray() method in getview in adapter. (magazine mag : newlist) { if (!oldlist.contains(mag)) { cachedadapter.add(mag); } }
i know it's not efficient way this, right care making work.
tried update list , call notifydatasetchanged(), gave same results. know might cause problem?
thank time.
- Get link
- X
- Other Apps
Comments
Post a Comment