android - getView() method of custom adapter never gets called -


i've read various threads on topic none of them seem apply code.

i'm trying populate fragment listview custom nearbyadapter. however, getview() method never gets called (as demonstrated logs not showing up). view seems appropriately attached fragment, demonstrated button in view showing up, not listview.

enter image description here

relevant nearbylistfragment.java code:

public class nearbylistfragment extends listfragment {      private int mimagesize;     private boolean mitemclicked;     private nearbyadapter madapter;      private list<place> places;     private latlng mlatestlocation;      private static final string tag = "nearbylistfragment";      public nearbylistfragment() {     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          log.d(tag, "nearbylistfragment created");          view view = inflater.inflate(r.layout.fragment_nearby, container, false);         return view;     }      //todo: asynchronously?     @override     public void onviewcreated(view view, bundle savedinstancestate) {          //load data source (nearbyplaces.java)          mlatestlocation = ((nearbyactivity) getactivity()).getmlatestlocation();         //fixme: hardcoding mlatestlocation michigan testing         //mlatestlocation = new latlng(44.182205, -84.506836);          places = loadattractionsfromlocation(mlatestlocation);         madapter = new nearbyadapter(getactivity(), places);          listview listview = (listview) view.findviewbyid(r.id.listview);         //setlistadapter(madapter);         listview.setadapter(madapter);          log.d(tag, "adapter set listview");         madapter.notifydatasetchanged();     }      private class nearbyadapter extends arrayadapter {          public list<place> placeslist;         private context mcontext;          public nearbyadapter(context context, list<place> places) {             super(context, r.layout.item_place);             mcontext = context;             placeslist = places;         }          @override         public view getview(int position, view convertview, viewgroup parent) {             // data item position             place place = (place) getitem(position);             //fixme: never gets called             log.d(tag, "place " + place.name);              // check if existing view being reused, otherwise inflate view             if (convertview == null) {                 convertview = layoutinflater.from(getcontext()).inflate(r.layout.item_place, parent, false);             }              // lookup view data population             textview tvname = (textview) convertview.findviewbyid(r.id.tvname);             textview tvdesc = (textview) convertview.findviewbyid(r.id.tvdesc);              // populate data template view using data object             tvname.settext(place.name);             tvdesc.settext(place.description);              // return completed view render on screen             return convertview;         }          @override         public long getitemid(int position) {             return position;         } 

the layout file of fragment, fragment_nearby.xml :

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <listview         android:id="@+id/listview"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:layout_above="@+id/btn_new">     </listview>     <button         android:id="@+id/btn_new"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerhorizontal="true"         android:layout_centervertical="true"         android:layout_marginbottom="20dp"         android:text="button"         android:width="170dp"         android:layout_alignparentbottom="true" />  </relativelayout> 

and layout file of item, item_place.xml :

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >     <textview         android:id="@+id/tvname"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="name" />     <textview         android:id="@+id/tvdesc"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="desc" /> </linearlayout>  

edit: want include reason downvote? when custom adapter list view has 129 upvotes?

the issue arrayadapter not know list places: use fix it:

private static class nearbyadapter extends arrayadapter<place> {    public nearbyadapter(context context, list<place> places) {       super(context, r.layout.item_place, places);       mcontext = context;       placeslist = places;    } } 

p/s: in case, think need more control set place data view. consider using baseadapter instead of arrayadapter.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -