android - How can I show ListView item from SlidingTab Fragment? -


this code want show listview item in slidingtab fragment. here sir post single post.xml public class tab1 extends fragment {

    @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {         view v =inflater.inflate(r.layout.productlist,container,false);         return v;      }  } 

this getting listviewitem

public class productlist extends listactivity {      // progress dialog     private progressdialog pdialog;       private static final string read_comments_url = "http://192.168.254.101/productlist.php";       private static final string tag_posts = "message";      private static final string tag_brand = "brand";      private static final string tag_category = "category";      private static final string tag_description = "description";      private static final string tag_code = "code";      private static final string tag_quantity = "quantity";      private static final string tag_unit = "unit";      private static final string tag_unitprice = "unitprice";      private jsonarray mcomments = null;      //manages of our comments in list.      private arraylist<hashmap<string, string>> mcommentlist;      @override      protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);           setcontentview(r.layout.productlist);      }       @override      protected void onresume() {          // todo auto-generated method stub          super.onresume();          //loading comments via asynctask          new loadcomments().execute();      }       public void updatejsondata() {           mcommentlist = new arraylist<hashmap<string, string>>();          jsonparser jparser = new jsonparser();          jsonobject json = jparser.getjsonfromurl(read_comments_url);           try {               mcomments = json.getjsonarray(tag_posts);              (int = 0; < mcomments.length(); i++) {                  jsonobject c = mcomments.getjsonobject(i);                  //gets content of each tag                  string brand = c.getstring(tag_brand);                  string category = c.getstring(tag_category);                  string description = c.getstring(tag_description);                  string code = c.getstring(tag_code);                  string quantity = c.getstring(tag_quantity);                  string unit = c.getstring(tag_unit);                  string unitprice = c.getstring(tag_unitprice);                   hashmap<string, string> map = new hashmap<string, string>();                  map.put(tag_brand, brand);                  map.put(tag_category, category);                  map.put(tag_description, description);                  map.put(tag_code, code);                  map.put(tag_quantity, quantity);                  map.put(tag_unit, unit);                  map.put(tag_unitprice, unitprice);                  mcommentlist.add(map);              }          } catch (jsonexception e) {              e.printstacktrace();          }      }      private void updatelist() {          listadapter adapter = new simpleadapter(this, mcommentlist,                  r.layout.single_post, new string[] { tag_brand, tag_category,                  tag_description, tag_code, tag_quantity, tag_unit, tag_unitprice}, new int[]{ r.id.brand, r.id.category,                  r.id.description, r.id.code, r.id.quantity, r.id.unit, r.id.price });          setlistadapter(adapter);           listview lv = getlistview();          lv.setonitemclicklistener(new onitemclicklistener() {              @override              public void onitemclick(adapterview<?> parent, view view,                                      int position, long id) {                }          });      }      public class loadcomments extends asynctask<void, void, boolean> {          @override          protected void onpreexecute() {              super.onpreexecute();              pdialog = new progressdialog(productlist.this);              pdialog.setmessage("loading products...");              pdialog.setindeterminate(false);              pdialog.setcancelable(true);              pdialog.show();          }          @override          protected boolean doinbackground(void... arg0) {              updatejsondata();              return null;          }          @override          protected void onpostexecute(boolean result) {              super.onpostexecute(result);              pdialog.dismiss();              updatelist();          }      }  } 

productlist.xml

android:layout_width="match_parent"  android:layout_height="match_parent"  android:background="#fff" >  <linearlayout      android:id="@+id/top_layover"      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:layout_alignparentleft="true"      android:layout_alignparenttop="true"      android:orientation="vertical" >      <textview          android:layout_height="wrap_content"          android:layout_gravity="center"          android:gravity="center"          android:text="products"          android:textappearance="?android:attr/textappearancelarge"         android:layout_width="wrap_content" />  </linearlayout>  <listview      android:id="@android:id/list"      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:layout_above="@+id/bottom_layover"      android:layout_below="@+id/top_layover"      android:background="#fff"      android:divider="@android:color/transparent"      android:scrollbars="none" />  <linearlayout      android:id="@+id/bottom_layover"      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:layout_alignparentbottom="true"      android:layout_alignparentleft="true"       android:orientation="horizontal"      android:weightsum="2" >      <linearlayout          android:layout_width="0dp"          android:layout_height="wrap_content"          android:layout_weight="1"          android:orientation="vertical" >      </linearlayout>  </linearlayout> 

single_post.xml

android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:background="#f0f0f0"  android:orientation="vertical" >  <linearlayout     android:id="@+id/box"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_margin="2dp"       android:orientation="horizontal" >      <linearlayout         android:layout_width="match_parent"          android:layout_height="wrap_content"          android:orientation="vertical"          android:paddingbottom="5dp"          android:background="#ffffff">          <linearlayout             android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="horizontal">              <textview                 android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:paddingleft="5dp"                  android:text="brand: ">              </textview>              <textview                  android:id="@+id/brand"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:textcolor="#5d5d5d"                  android:textstyle="bold" >              </textview>          </linearlayout>          <linearlayout              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="horizontal">               <textview                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:paddingleft="5dp"                  android:text="category: " >              </textview>              <textview                  android:id="@+id/category"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:textcolor="#5d5d5d"                  android:textstyle="bold" >              </textview>          </linearlayout>           <linearlayout              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="horizontal">               <textview                 android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:paddingleft="5dp"                  android:text="description: " >              </textview>              <textview                  android:id="@+id/description"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:textcolor="#5d5d5d"                  android:textstyle="bold" >              </textview>          </linearlayout>          <linearlayout              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="horizontal">               <textview                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:paddingleft="5dp"                  android:text="code: " >              </textview>              <textview                  android:id="@+id/code"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:textcolor="#5d5d5d"                  android:textstyle="bold" >              </textview>          </linearlayout>            <linearlayout             android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="horizontal">              <textview                  android:layout_width="wrap_content"                  android:layout_height="wrap_content" 

android:gravity="left"

                android:paddingleft="5dp"                  android:text="quantity: ">              </textview>              <textview                  android:id="@+id/quantity"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:textcolor="#5d5d5d"                  android:textstyle="bold" >              </textview>          </linearlayout>           <linearlayout              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="horizontal">              <textview                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:paddingleft="5dp"                  android:text="unit: " >              </textview>              <textview                  android:id="@+id/unit"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:textcolor="#5d5d5d"                  android:textstyle="bold" >              </textview>          </linearlayout>            <linearlayout              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="horizontal">              <textview                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:paddingleft="5dp"                  android:text="price: " >              </textview>              <textview                  android:id="@+id/price"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:gravity="left"                  android:textcolor="#5d5d5d"                  android:textstyle="bold" >              </textview>          </linearlayout>      </linearlayout>  </linearlayout> 

your tab should extend listfragment.

public class tab extends listfragment{    //your existing code...    @override   public void onactivitycreated(bundle savedinstancestate) {       super.oncreate(savedinstancestate);        new loadcomments().execute();   }    @override   public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view v =inflater.inflate(r.layout.productlist,container,false);     return v;   }    //your existing code... } 

i didn't test code should work.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -