How can I make an android xml layout for Category and CategoryItem -


i'am new in using java , android studio , wondering how can make layout in 1 activity. myimage

what looking listview adapter

public class exampleadapter extends baseadapter {     list<product> products;     private activity context;      @override     public int getcount() {         return products.size();     }      public exampleadapter(list<product> products, activity context) {         this.products = products;         this.context = context;     }      @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) {         final product product = products.get(position);          viewholder holder;          if (convertview == null) {             layoutinflater inflater = context.getlayoutinflater();             convertview = inflater.inflate(r.layout.row_shopping_item, null);             holder = new viewholder(convertview);             convertview.settag(holder);         } else {             holder = (viewholder) convertview.gettag();         }         holder.getproducttextview().settext(product.getname());         holder.getproductimageview(). setimageresource(product.getpicture());          return convertview;     }      private class viewholder {         private final textview producttextview;         private final imageview productimageview;          private viewholder(view wrapperview) {             producttextview = (textview) wrapperview.findviewbyid(r.id.tvname);             productimageview = (textview) wrapperview.findviewbyid(r.id.ivpicture);          }          public textview getproducttextview() {             return producttextview;         }          public imageview getproductimageview() {             return productimageview;         }      } } 

this adapter needs layout define rows like. this

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="horizontal">      <imageview         android:layout_gravity="center_vertical"         android:layout_width="50dp"         android:id="@+id/ivpicture"         android:layout_height="50dp" />      <textview         android:id="@+id/tvname"         android:text="product 1"         android:layout_width="wrap_content"         android:layout_height="wrap_content" /> </linearlayout> 

lastly in activity want display overview need use listview , set adapter

final exampleadapter adapter = new exampleadapter(list, this); listview.setadapter(adapter); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -