android - the Staggered Grid View in view pager does not set the adapter properly -


my staggered grid view adapter works in api 19 or higher.but when run in api 17 or lower seen adapter not set properly.if change staggered grid view grid view works fine , shows adpter class work fine.but dont know problem.the images not set in staggered grid view .maybe cause view pager tis tab view xml viewpager:

<linearlayout 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"     android:orientation="vertical"     tools:context=".mainactivity">      <ir.hisis.cloth.slidingtablayout         android:id="@+id/tabs"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:elevation="2dp"         android:background="@color/colorprimary"/>      <android.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_height="match_parent"         android:layout_width="match_parent"         android:layout_weight="1">     </android.support.v4.view.viewpager>  </linearlayout> 

this staggered grid view xml:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent">      <com.etsy.android.grid.staggeredgridview         android:id="@+id/grid_view"         android:layout_width="match_parent"         android:layout_height="match_parent"         app:item_margin="8dp"         app:column_count="1" /> </framelayout> 

this main activity:

protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         settitle("");          // creating viewpageradapter , passing fragment manager, titles fot tabs , number of tabs.         adapter =  new tabspageradapter(getsupportfragmentmanager(),titles,numboftabs);          // assigning viewpager view , setting adapter         pager = (viewpager) findviewbyid(r.id.pager);         pager.setadapter(adapter);          // assiging sliding tab layout view         tabs = (slidingtablayout) findviewbyid(r.id.tabs);         tabs.setdistributeevenly(true); // make tabs fixed set true, makes tabs space evenly in available width          // setting custom color scroll bar indicator of tab view         tabs.setcustomtabcolorizer(new slidingtablayout.tabcolorizer() {             @override             public int getindicatorcolor(int position) {                 return getresources().getcolor(r.color.tabsscrollcolor);             }         }); 

the tab page adapter:

public class tabspageradapter extends fragmentstatepageradapter {      charsequence titles[];     int numboftabs;      public tabspageradapter(fragmentmanager fm,charsequence mtitles[], int mnumboftabsumb) {         super(fm);          this.titles = mtitles;         this.numboftabs = mnumboftabsumb;      }     @override     public fragment getitem(int position) {          if(position == 0)         {             return new mainfragment();         }         else if(position == 1)         {             return new mainfragment();         }         else         {             return new mainfragment();         }      }       @override     public charsequence getpagetitle(int position) {         return titles[position];     }       @override     public int getcount() {         return numboftabs;     } } 

and main fragment:

    public  class mainfragment extends fragment {          public mainfragment() {          }         @override         public view oncreateview(layoutinflater inflater, viewgroup container,                                  bundle savedinstancestate) {              view rootview = inflater.inflate(r.layout.fragment_main, container,                     false);             return rootview;         }           @override         public void onactivitycreated(bundle savedinstancestate) {             super.onactivitycreated(savedinstancestate);             imageadapter adapt;             staggeredgridview gridview = (staggeredgridview) getview().findviewbyid(r.id.grid_view);             adapt= new imageadapter(getactivity());             gridview.setadapter(adapt);         } image adpter: public class imageadapter extends baseadapter {     private context mcontext;     public string tag = "base adapter";     activity activity;     public imageadapter(activity a) {         activity = a;         mcontext = activity.getapplicationcontext();     }      public int getcount() {         return mthumbids.length;     }      public object getitem(int position) {         return null;     }      public long getitemid(int position) {         return 0;     }      // create new imageview each item referenced adapter     public view getview(int position, view convertview, viewgroup parent) {         view imageitem;         log.e("item","");         if (convertview == null) {             layoutinflater inflater = activity.getlayoutinflater();             imageitem = inflater.inflate(r.layout.image_item, null);              imageitemviewholder tag = new imageitemviewholder();             tag.image = (imageview) imageitem.findviewbyid(r.id.image);             tag.tagscontainer = (linearlayout) imageitem.findviewbyid(r.id.tags_container);             tag.likeimage = (imageview) imageitem.findviewbyid(r.id.like_image);             setsharelongclicklistenerforimage(tag.image);             imageitem.settag(tag);         } else {             imageitem =  convertview;         }          imageitemviewholder tag = (imageitemviewholder) imageitem.gettag();         imageview img = tag.image;         img.setimageresource(mthumbids[position]);          return imageitem;     }      private void setsharelongclicklistenerforimage(imageview image){         image.setonlongclicklistener(new view.onlongclicklistener() {              @override             public boolean onlongclick(view arg0) {                 try{                     log.wtf(tag, "starting share image");                     utils.shareimage((imageview) arg0, activity);                 }                 catch(filenotfoundexception e){                     toast.maketext(arg0.getcontext(), activity.getstring(r.string.external_storage_is_uavailable), toast.length_long).show();                 }catch (ioexception e) {                     toast.maketext(arg0.getcontext(), activity.getstring(r.string.proble_with_external_storage), toast.length_long).show();                 }                  return true;             }         });     }       // references our images     private integer[] mthumbids = {             r.drawable.sample_2, r.drawable.sample_3,             r.drawable.sample_4, r.drawable.sample_5,             r.drawable.sample_6, r.drawable.sample_7,             r.drawable.sample_0, r.drawable.sample_1,             r.drawable.sample_2, r.drawable.sample_3,             r.drawable.sample_4, r.drawable.sample_5,             r.drawable.sample_6, r.drawable.sample_7,             r.drawable.sample_0, r.drawable.sample_1,             r.drawable.sample_2, r.drawable.sample_3,             r.drawable.sample_4, r.drawable.sample_5,             r.drawable.sample_6, r.drawable.sample_7     };      public static class imageitemviewholder{         public imageview image;         public linearlayout tagscontainer;         public imageview likeimage;     } 

change value of minsdkversion manifest of library project 9

<uses-sdk android:minsdkversion="10"/> 

with

<uses-sdk android:minsdkversion="9"/> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -