java - How can I cache custom views in my ListView Adapter? -



java - How can I cache custom views in my ListView Adapter? -

in imageadapter (extends baseadapter), each view custom view called imagetapview. it's separate class extends relativelayout own layout file starts <merge>. class contains click listeners, loaders images each imagetapview downloads , displays internet, animations happen on click.

here's imageadapter constructor:

public class imageadapter extends baseadapter { private context context; private jsonarray posts; private string baseurl; private hashmap views = new hashmap(); public imageadapter(context _context, jsonarray _posts, string _baseurl){ context = _context; posts = _posts; baseurl = _baseurl; } ...etc }

in imageadapter.getview works fine if like:

public view getview(int position, view convertview, viewgroup parent){ // create new imagetapview jsonobject thispost = posts.getjsonobject(position); convertview = new imagetapview(context, thispost); homecoming convertview; }

but means android creating new imagetapview every time calls getview instead of replacing info in inflated view. think it'd way harder go in , replace each field , reset animations on getview, not mention, i'd user see in interaction imagetapview left off (e.g. zoomed in on image or in middle of animation).

i tried saving each view hashmap called views:

public view getview(int position, view convertview, viewgroup parent){ if(views.containskey(position)) homecoming (imagetapview) views.get(position); // create new imagetapview jsonobject thispost = posts.getjsonobject(position); convertview = new imagetapview(context, thispost); views.put(position, convertview); homecoming convertview; }

but unusual behavior. imagetapviews on, say, step 2 of 3 steps of interaction (start state, zoomed state, info overlay shown state), things strange. don't seem pick left off , don't respond clicks proper way fresh imagetapview would.

so there standard way of caching objects or custom objects in listview? should extending arrayadapter instead, or problem same in getview function?

thanks in advance!

try ,you need create method setpost() set post

public view getview(int position, view convertview, viewgroup parent){ // create new imagetapview jsonobject thispost = posts.getjsonobject(position); if(convertview==null) convertview = new imagetapview(context, thispost); else{ ((imagetapview)convertview).setpost(thispost); } homecoming convertview; }

java android android-listview

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -