android - How can I add a progress bar footer at the bottom of my grid view? -
how can add together progress bar footer @ bottom of grid view visible when load more grid view items, , hide progress bar when loading of requested info done? need know how implement ui on xml file can applied on screen sizes. below, code grid view:
<gridview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/grid_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numcolumns="auto_fit" android:gravity="center" android:stretchmode="columnwidth" android:background="#ffb4d9"> </gridview>
gridviewactivity
public class gridviewactivity extends activity implements abslistview.onscrolllistener, abslistview.onitemclicklistener{ private gridview gridview; private gridviewimageadapter adapter; private utils utils; private generatedata generatedata; private arraylist<hashmap<string, string>> galleryattributes; private int columnwidth; private int urlpageindex = 1; private boolean hasrequestedmore; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_grid_view); settitle("gallery"); gridview = (gridview) findviewbyid(r.id.grid_view); utils = new utils(this); initializegridlayout(); galleryattributes = new arraylist<hashmap<string, string>>(); generatedata = utils.new generatedata(urlpageindex); seek { galleryattributes.addall(generatedata.execute().get()); } grab (interruptedexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (executionexception e) { // todo auto-generated grab block e.printstacktrace(); } adapter = new gridviewimageadapter(gridviewactivity.this, galleryattributes , columnwidth); gridview.setadapter(adapter); gridview.setonscrolllistener(this); gridview.setonitemclicklistener(this); } public void initializegridlayout() { resources r = getresources(); float padding = typedvalue.applydimension(typedvalue.complex_unit_dip,appconstant.grid_padding, r.getdisplaymetrics()); columnwidth = (int) ((utils.getscreenwidth() - ((appconstant.num_of_columns + 1) * padding)) / appconstant.num_of_columns); gridview.setnumcolumns(appconstant.num_of_columns); gridview.setcolumnwidth(columnwidth); gridview.setstretchmode(gridview.no_stretch); gridview.setpadding((int) padding, (int) padding, (int) padding,(int) padding); gridview.sethorizontalspacing((int) padding); gridview.setverticalspacing((int) padding); } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // todo auto-generated method stub intent intent = new intent(gridviewactivity.this, carouselviewactivity.class); intent.putextra("position", position); intent.putextra("galleryattributes", galleryattributes); startactivity(intent); log.e("onitemclick: ", ""+position); } @override public void onscrollstatechanged(abslistview view, int scrollstate) { // todo auto-generated method stub log.e("onscrollstatechanged: ", ""+scrollstate); } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { // todo auto-generated method stub log.e("onscroll: ","firstvisibleitem:"+firstvisibleitem+" visibleitemcount:"+visibleitemcount+" totalitemcount:"+totalitemcount); if(!hasrequestedmore){ int lastinscreen = firstvisibleitem+visibleitemcount; if(lastinscreen>=totalitemcount){ hasrequestedmore = true; onloadmoreitems(); } } } public void onloadmoreitems(){ if(urlpageindex<3){ urlpageindex++; generatedata = utils.new generatedata(urlpageindex); seek { galleryattributes.addall(generatedata.execute().get()); } grab (interruptedexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (executionexception e) { // todo auto-generated grab block e.printstacktrace(); } adapter.notifydatasetchanged(); hasrequestedmore = false; } } }
this utils class, info requested:
public class utils { private context context; private activity activity; private progressdialog progress; public utils(){} public utils(context context){ this.context = context; } public class generatedata extends asynctask<void, void, arraylist<hashmap<string, string>>>{ private jsonarray datajsonarr; private jsonparser jparser; private jsonobject json; private jsonobject c; private hashmap<string, string> map; private arraylist<hashmap<string,string>> galleryattributes; private int urlpageindex; public generatedata(int urlpageindex){ this.urlpageindex = urlpageindex; new initializejsonarray().execute(); } @override protected arraylist<hashmap<string, string>> doinbackground( void... params) { // todo auto-generated method stub try{ for(int = 0; i< datajsonarr.length(); i++) { c = datajsonarr.getjsonobject(i); map = new hashmap<string, string>(); map.put("link", c.getstring("link")); galleryattributes.add(map); } } grab (jsonexception e) { e.printstacktrace(); } homecoming galleryattributes; } public class initializejsonarray extends asynctask<void, void, void>{ @override protected void doinbackground(void... params) { // todo auto-generated method stub datajsonarr = null; jparser = new jsonparser(); json = jparser.getjsonfromurl(appconstant.json_url+urlpageindex); seek { datajsonarr = json.getjsonarray(appconstant.json_array_name); } grab (jsonexception e) { // todo auto-generated grab block e.printstacktrace(); } galleryattributes = new arraylist<hashmap<string, string>>(); galleryattributes.ensurecapacity(datajsonarr.length()); homecoming null; } } } @suppresslint("newapi") public int getscreenwidth() { int columnwidth; windowmanager wm = (windowmanager) context.getsystemservice(context.window_service); display display = wm.getdefaultdisplay(); final point point = new point(); seek { display.getsize(point); } grab (java.lang.nosuchmethoderror ignore) { point.x = display.getwidth(); point.y = display.getheight(); } columnwidth = point.x; homecoming columnwidth; }
}
and finally, adapter class :
public class gridviewimageadapter extends baseadapter{ private context context; private int imagewidth; private arraylist<hashmap<string, string>> galleryattributes; imageview imageview; public gridviewimageadapter(context context, arraylist<hashmap<string, string>> galleryattributes, int imagewidth){ this.galleryattributes = galleryattributes; this.context = context; this.imagewidth = imagewidth; } @override public int getcount() { // todo auto-generated method stub homecoming galleryattributes.size(); } @override public object getitem(int position) { // todo auto-generated method stub homecoming galleryattributes.get(position); } @override public long getitemid(int position) { // todo auto-generated method stub homecoming position; } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) { imageview = new imageview(context); } else { imageview = (imageview) convertview; } picasso.with(context).load(galleryattributes.get(position).get("link")).placeholder(r.drawable.loadingimage).into(imageview); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setlayoutparams(new gridview.layoutparams(imagewidth,imagewidth)); homecoming imageview; }
}
try positioning progressdialog
in bottom this:
//in asynctask progressdialog progressdialog; //in onpreexecute progressdialog = new progressdialog(context); progressdialog.setmessage("fetching images"); progressdialog.setprogressstyle(progressdialog.style_spinner); progressdialog.setindeterminate(true); progressdialog.setcancelable(false); progressdialog.getwindow().setgravity(gravity.bottom); progressdialog.show(); //in onpostexecute progressdialog.dismiss();
hope helps.
android footer android-gridview android-progressbar android-lazyloading
No comments:
Post a Comment