android - Adapter shows items sometimes -


i have 2 baseadapter, 1 posts , other answers posts. first 1 works , shows items. when press see answers of post adapter work (the answeradapater):

public adapteranswers(context context, arraylist<hashmap<string, string>> list) {     this.context=context;     searcharraylist=list;     inflater = ((activity) context).getlayoutinflater(); }  @override public int getcount() {     if (searcharraylist != null)         return searcharraylist.size();     else return 5; }    public view getview(final int position, view convertview, viewgroup parent) {     view view = convertview;     dataofarow = searcharraylist.get(position);     if (view == null) {         view = inflater.inflate(r.layout.comment_item, parent, false);          log.d("converview", "null" + view.gettag());      }     textview comment= (textview) view.findviewbyid(r.id.txt_comment);     comment.settext(dataofarow.get(tag_posttext));     return view;} 

i set adapter listview in oncreate() of answers activity:

 bundle extras = getintent().getextras();     string id=extras.getstring("id");      readanswers readanswers=new readanswers();     answerdata=readanswers.returnparam(id);      adapter=new adapteranswers(this,answerdata);     listview.setadapter(adapter); 

the other adapter (myadapter) same:

public myadapter(context context, arraylist<hashmap<string, string>> list) {     this.context=context;     searcharraylist=list;     inflater = ((activity) context).getlayoutinflater(); public int getcount() {     if (searcharraylist != null)         return searcharraylist.size();     else return 5; }  @override public view getview(final int position, final view convertview, viewgroup parent) {     view view = convertview;     dataofarow = searcharraylist.get(position);      if (view == null) {         view = inflater.inflate(r.layout.comment_item, parent, false); // <-- parent second argument      }     textview comment= (textview) view.findviewbyid(r.id.txt_comment); seeanswers.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             dataofarow = searcharraylist.get(position);             string idofcomment=dataofarow.get(tag_id);             intent intent=new intent(context, answers.class);             intent.putextra("id", idofcomment);             context.startactivity(intent);           }     });     return view;} 

and set listview in same way.

 readposts redposts=new readposts();     allthedata=redposts.returnparam("request data");     myadapter= new myadapter(this,allthedata);     listview.setadapter(myadapter); 

my problem few times adapter works. problem started when move server localhost web host. adapter doesn't show items because doesn't call getview, because arraylist appears size 0. when log other adapter size 0 works (the post adapter).

when change inflate r.layout.comment_item works first time (but not always). problem weird , i've tried lot of things. welcome!

replace code adapter class

public view getview(final int position, view convertview, viewgroup parent) {      viewholder viewholder;      if(converview == null){        viewholder = new viewholder();        convertview = inflater.inflate(r.layout.comment_item, parent, false);          viewholder.comment = (textview) convertview.findviewbyid(r.id.txt_comment);        viewholder.comment.settag(position);         convertview.settag(viewholder);     } else {        viewholder = (viewholder)convertview.gettag();     }         viewholder.comment.settext(dataofarow.get(tag_posttext));        return convertview();     }      private class viewholder{         textview comment;     } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -