android - i want to slide images ,images are coming through json -
i want slide images ,images coming through json . using of code coming in list view . want ten images should come slider .how van this?
i want slide image 1 one in horizontal.
i getting image
see in image .
mainactivity
public class mainactivity extends activity { // log tag private static final string tag = mainactivity.class.getsimplename(); private static final string url = "http://20dde605.ngrok.io/api/v1/restaurants/get_featured_restaurants"; // movies json url //private static final string url = "http://api.androidhive.info/json/movies.json"; private progressdialog pdialog; private list<movie> movielist = new arraylist<movie>(); private listview listview; private customlistadapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); listview = (listview) findviewbyid(r.id.list); adapter = new customlistadapter(this, movielist); listview.setadapter(adapter); pdialog = new progressdialog(this); // showing progress dialog before making http request pdialog.setmessage("loading..."); pdialog.show(); // changing action bar color getactionbar().setbackgrounddrawable( new colordrawable(color.parsecolor("#1b1b1b"))); // creating volley request obj jsonarrayrequest moviereq = new jsonarrayrequest(url, new response.listener<jsonarray>() { @override public void onresponse(jsonarray response) { log.d(tag, response.tostring()); hidepdialog(); // parsing json (int = 0; < response.length(); i++) { try { jsonobject obj = response.getjsonobject(i); movie movie = new movie(); //movie.settitle(obj.getstring("title")); //movie.setname(obj.getstring("name")); //movie.setthumbnailurl(obj.getstring("image")); movie.setthumbnailurl(obj.getstring("org_image_url")); //movie.setaverage_ratings(obj.getstring("average_ratings")); //movie.setcuisine(obj.getstring("cuisine")); //movie.setaddress(obj.getjsonobject("address").getstring("area")); //movie.setaddress(obj.getstring("address")); //movie.setyear(obj.getint("releaseyear")); // genre json array /*jsonarray genrearry = obj.getjsonarray("genre"); arraylist<string> genre = new arraylist<string>(); (int j = 0; j < genrearry.length(); j++) { genre.add((string) genrearry.get(j)); } movie.setgenre(genre);*/ // adding movie movies array movielist.add(movie); } catch (jsonexception e) { e.printstacktrace(); } } // notifying list adapter data changes // renders list view updated data adapter.notifydatasetchanged(); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d(tag, "error: " + error.getmessage()); hidepdialog(); } }); // adding request request queue appcontroller.getinstance().addtorequestqueue(moviereq); } @override public void ondestroy() { super.ondestroy(); hidepdialog(); } private void hidepdialog() { if (pdialog != null) { pdialog.dismiss(); pdialog = null; } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
appcontroller.java
public class appcontroller extends application { public static final string tag = appcontroller.class.getsimplename(); private requestqueue mrequestqueue; private imageloader mimageloader; private static appcontroller minstance; @override public void oncreate() { super.oncreate(); minstance = this; } public static synchronized appcontroller getinstance() { return minstance; } public requestqueue getrequestqueue() { if (mrequestqueue == null) { mrequestqueue = volley.newrequestqueue(getapplicationcontext()); } return mrequestqueue; } public imageloader getimageloader() { getrequestqueue(); if (mimageloader == null) { mimageloader = new imageloader(this.mrequestqueue, new lrubitmapcache()); } return this.mimageloader; } public <t> void addtorequestqueue(request<t> req, string tag) { // set default tag if tag empty req.settag(textutils.isempty(tag) ? tag : tag); getrequestqueue().add(req); } public <t> void addtorequestqueue(request<t> req) { req.settag(tag); getrequestqueue().add(req); } public void cancelpendingrequests(object tag) { if (mrequestqueue != null) { mrequestqueue.cancelall(tag); } } }
model -movie
public class movie { private string name, thumbnailurl; //private int year; private string average_ratings,area,cuisine,address; // private arraylist<string> genre; public movie() { } public movie(string name, string thumbnailurl, string average_ratings,string area,string cuisine,string address ) { this.name = name; this.thumbnailurl = thumbnailurl; //this.year = year; this.average_ratings = average_ratings; this.area=area; this.cuisine=cuisine; this.address=address; //this.genre = genre; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getthumbnailurl() { return thumbnailurl; } public void setthumbnailurl(string thumbnailurl) { this.thumbnailurl = thumbnailurl; } /*public int getyear() { return year; }*/ /*public void setyear(int year) { this.year = year; }*/ public string getaverage_ratings() { return average_ratings; } public void setaverage_ratings(string average_ratings) { this.average_ratings = average_ratings; } public string getaddress() { return address; } public void setaddress(string address) { this.address = address; } public string getcuisine() { return cuisine; } public void setcuisine(string cuisine) { this.cuisine = cuisine; } /*public arraylist<string> getgenre() { return genre; } public void setgenre(arraylist<string> genre) { this.genre = genre; } */ }
lrubitmapcache
public class lrubitmapcache extends lrucache<string, bitmap> implements imagecache { public static int getdefaultlrucachesize() { final int maxmemory = (int) (runtime.getruntime().maxmemory() / 1024); final int cachesize = maxmemory / 8; return cachesize; } public lrubitmapcache() { this(getdefaultlrucachesize()); } public lrubitmapcache(int sizeinkilobytes) { super(sizeinkilobytes); } @override protected int sizeof(string key, bitmap value) { return value.getrowbytes() * value.getheight() / 1024; } @override public bitmap getbitmap(string url) { return get(url); } @override public void putbitmap(string url, bitmap bitmap) { put(url, bitmap); } }
use <viewflipper>
or <viewpager>
or use imageslider library.
Comments
Post a Comment