android - Why doesn`t my listview show any elements? -


i have viewpager want display listviews with. using single fragment has custom listview.

fragment xml(fragment_list_view):

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.popcristian.licenta.listviewfragment" >      <listview          android:id="@+id/productslistview"         android:layout_width="match_parent"         android:layout_height="match_parent" />  </framelayout> 


list item xml(fragment_list_item):

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <textview          android:id="@+id/producttitle"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margintop="8dp"         android:layout_marginstart="10dp"         android:layout_marginend="16dp"         android:singleline="true"         android:textstyle="bold"         android:textsize="17sp"         android:text="test title"/>      <textview          android:id="@+id/productdescription"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margintop="2dp"         android:layout_marginstart="10dp"         android:layout_marginend="16dp"         android:layout_below="@+id/producttitle"         android:maxlines="2"         android:textsize="13sp"         android:text="some text" />      <textview          android:id="@+id/productcategory"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margintop="2dp"         android:layout_marginstart="10dp"         android:layout_below="@+id/productdescription"         android:textsize="12sp"         android:textstyle="italic"         android:textcolor="#c0c0c0"         android:text="category: men / jeans" />      <textview          android:id="@+id/productprice"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginend="16dp"         android:layout_alignparentend="true"         android:textsize="17sp"         android:textstyle="bold"         android:textcolor="#95c957"         android:text="500$" />  </relativelayout> 


fragment trying display:

public class listviewfragment extends fragment {      private listview listview;     private productslistviewadapter adapter;     private list<string> params;     private int index;     private string category, subcategory;     private list<product> products;     private textview producttitle, productdescription, productcategory, productprice;      public listviewfragment(int index, string category, string subcategory, list<product> products) {         this.index = index;         this.category = category;         this.subcategory = subcategory;         this.products = products;     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view view = inflater.inflate(r.layout.fragment_list_view, null);          product product = products.get(0);         string title = product.gettitle();         log.d("title", title); // prints out title         listview = (listview) view.findviewbyid(r.id.productslistview);         adapter = new productslistviewadapter(getactivity(), products);         listview.setadapter(adapter);          return inflater.inflate(r.layout.fragment_list_view, container, false);     }  } 


adapter:

public class productslistviewadapter extends baseadapter{      private activity activity;     private list<product> products;     private layoutinflater inflater;      public productslistviewadapter(activity activity, list<product> products) {         this.activity = activity;         this.products = products;     }      @override     public int getcount() {         return products.size();     }      @override     public object getitem(int position) {         return products.get(position);     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {          if(inflater == null)             inflater = (layoutinflater) activity.getsystemservice(context.layout_inflater_service);         if(convertview == null)             convertview = inflater.inflate(r.layout.fragment_list_item, null);          textview title = (textview) convertview.findviewbyid(r.id.producttitle);         textview description = (textview) convertview.findviewbyid(r.id.productdescription);         textview category = (textview) convertview.findviewbyid(r.id.productcategory);         textview price = (textview) convertview.findviewbyid(r.id.productprice);          product product = products.get(position);          title.settext(product.gettitle());         description.settext(product.getdescription());         category.settext(product.getcategory());         price.settext(product.getprice());          return convertview;     }  } 


when run code nothing gets displayed in listview. doing wrong?

your returning in fragment:

return inflater.inflate(r.layout.fragment_list_view, container, false); 

however adapter set in different view:

view view = inflater.inflate(r.layout.fragment_list_view, null); product product = products.get(0); string title = product.gettitle(); log.d("title", title); // prints out title listview = (listview) view.findviewbyid(r.id.productslistview); adapter = new productslistviewadapter(getactivity(), products); listview.setadapter(adapter); 

which never used because view returned.

change return inflater.inflate(r.layout.fragment_list_view, container, false); return view;


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -