android - ListView displaying nothing with custom adapter -


as title states, i'm having troubles getting custom listview work properly. app displays nothing on list, , gives blank white screen. tested data simple list have setup, , worked fine. i'm hoping can see haven't. thanks.

history.java

public class history {     public string score;     public string gametype;     public int icon;      public history() {         super();     }      public history(string score, string gametype, int icon) {         super();         this.score = score;         this.gametype = gametype;         this.icon = icon;     } } 

historyadapter.java

public class historyadapter extends arrayadapter<history> {      context context;     int layoutresid;     history data[] = null;      public historyadapter(context context, int layoutresid, history[] data) {         super(context, layoutresid, data);         this.layoutresid = layoutresid;         this.context = context;         this.data = data;     }      @override     public view getview(int position, view convertview, viewgroup parent) {         historyholder holder = null;          if(convertview == null)         {             layoutinflater inflater = ((activity)context).getlayoutinflater();             convertview = inflater.inflate(layoutresid, parent, false);              holder = new historyholder();             holder.imageicon = (imageview)convertview.findviewbyid(r.id.icon);             holder.texttitle = (textview)convertview.findviewbyid(r.id.gametype);             holder.textscore = (textview)convertview.findviewbyid(r.id.score);              convertview.settag(holder);         }         else         {             holder = (historyholder)convertview.gettag();         }          history history = data[position];         holder.textscore.settext(history.score);         holder.texttitle.settext(history.gametype);         holder.imageicon.setimageresource(history.icon);           return convertview;     }      static class historyholder     {         imageview imageicon;         textview texttitle;         textview textscore;     } } 

implementation

history[] historydata = new history[games.length()];   for(int = 0; < games.length(); i++) {                     jsonobject c = games.getjsonobject(i);                     jsonobject gamestats = games.getjsonobject(i).getjsonobject(tag_stats);                     type[i] = c.getstring(tag_type);                     champid[i] = c.getstring("championid");                     cs[i] = gamestats.getstring("minionskilled");                     kills[i] = gamestats.getstring("championskilled");                     deaths[i] = gamestats.getstring("numdeaths");                     assists[i] = gamestats.getstring("assists");                     win[i] = gamestats.getstring("win");                      if(win[i].equals("true"))                         win[i] = "victory";                     else                         win[i] = "defeat";                      if(type[i].equals("ranked_solo_5x5"))                         type[i] = "ranked (solo)";                      if(type[i].equals("cap_5x5"))                         type[i] = "teambuilder";                      if(type[i].equals("normal"))                         type[i] = "unranked";                      score[i] = kills[i] +"/" + deaths[i] + "/" + assists[i];                      historydata[i] = new history(score[i], champid[i], r.drawable.ic_launcher); // placeholder image                  }                  if(historydata == null) {                     historydata[0] = new history("no game found", "n/a", r.drawable.ic_launcher);                     log.i("data", "" + historydata);                 }                  adapter = new historyadapter(matchhistoryactivity.this,                         r.layout.list_adapter,                         historydata);                  list.setadapter(adapter); 

listview.xml

<?xml version="1.0" encoding="utf-8"?>  <listview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/list"     android:background="#111111">      </listview> 

list_item.xml

<relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="?android:attr/listpreferreditemheight"     android:background="#111111"     android:padding="6dip" >      <imageview         android:id="@+id/icon"         android:layout_width="wrap_content"         android:layout_height="fill_parent"         android:layout_alignparentbottom="true"         android:layout_alignparenttop="true"         android:layout_marginright="6dip"         android:contentdescription="todo"         android:src="@drawable/ic_launcher" />      <textview         android:id="@+id/score"         android:textcolor="#c49246"         android:layout_width="fill_parent"         android:layout_height="26dip"         android:layout_alignparentbottom="true"         android:layout_alignparentright="true"         android:layout_marginleft="5dp"         android:layout_torightof="@id/icon"         android:ellipsize="marquee"         android:singleline="true"         android:text="0/0/0 kda"         android:textsize="12sp" />      <textview         android:id="@+id/gametype"         android:textcolor="#c49246"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_above="@id/score"         android:layout_alignparentright="true"         android:layout_alignparenttop="true"         android:layout_alignwithparentifmissing="true"         android:layout_marginleft="5dp"         android:layout_torightof="@id/icon"         android:gravity="center_vertical"         android:textsize="16sp" />  </relativelayout> 

the code you've included seems fine, point can fail in loop create historydata array.

for reason might not processing correctly, instance, json attributes not being defined sometimes.

you can use try block , catch jsonexception see what's wrong, , add several log.d() sentences know where's culprit.

for instance:

try {   cs[i] = gamestats.getstring("minionskilled"); } catch (jsonexception) { e.printstacktrace(); } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -