java - my viewpager have bad performance in android 6 -


i create slider adapter , activity , code works fine in android 4.4 kitkat in android 6 have crash or don't show me images , .... have problem appcompact ? don't know how fix problem. adapter

public class screenshootsadapter extends pageradapter {      private int[] image_resources={            r.drawable.walkthrough1,             r.drawable.walkthrough2,             r.drawable.walkthrough3,             r.drawable.walkthrough4,             r.drawable.walkthrough5,             r.drawable.walkthrough6,      };      private context ctx;      private layoutinflater layoutinflater;      public screenshootsadapter(context ctx){         this.ctx=ctx;     }       @override     public int getcount() {         return image_resources.length;     }      @override     public boolean isviewfromobject(view view, object object) {         return (view==(linearlayout) object);     }      @override     public object instantiateitem(viewgroup container, int position){         layoutinflater =(layoutinflater) ctx.getsystemservice(context.layout_inflater_service);          view item_view= layoutinflater.inflate(r.layout.screenshoots,container,false);          imageview imageview=(imageview) item_view.findviewbyid(r.id.slider_image);          imageview.setimageresource(image_resources[position]);          container.addview(item_view);          return item_view;     }      @override     public void destroyitem(viewgroup container,int position,object object)     {         container.removeview((linearlayout) object);     } } 

activity

public class apptutorialactivity extends appcompatactivity {      viewpager viewpager;     screenshootsadapter adapter;     typeface typeface;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_app_tutorial);           viewpager=(viewpager) findviewbyid(r.id.screenshoot_slider);          adapter=new screenshootsadapter(this);          viewpager.setadapter(adapter);          tablayout tablayout = (tablayout) findviewbyid(r.id.tab_layout);          tablayout.setupwithviewpager(viewpager, true);          //button btnback=(button)findviewbyid(r.id.btn_back);         textview textback=(textview) findviewbyid(r.id.text_back);          typeface=typeface.createfromasset(getassets(),"font/iransansmobile.ttf");          textback.settypeface(typeface);          textback.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 finish();             }         });         //btnback.settypeface(typeface);     } } 

create array of images in strings folder

<?xml version="1.0" encoding="utf-8"?> <resources>     <array name="list">         <item>@drawable/walkthrough1</item>         <item>@drawable/walkthrough2</item>         <item>@drawable/walkthrough3</item>         <item>@drawable/walkthrough4</item>         <item>@drawable/walkthrough5</item>         <item>@drawable/walkthrough6</item>     </array> </resources> 

then in apptutorialactivity activity initialize array

typedarray list = getresources().obtaintypedarray(r.array.list); 

pass array screenshootsadapter

public screenshootsadapter(context ctx,typedarray list){     this.ctx=ctx;     mlist=list } 

load image tpedarray list

imageview.setimageresource(list.getresourceid(position, -1)); 

also try use image loading libraries glide or picasso helps loading easily.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -