android - display ProgressBar ontop of ListView -
asking simplest question, have searched lot related problem didn't find solution. have layout in android application in i'm using listview
progressbar
. task in doing in asynctask class. want show progress bar in centre of activity before loading list. can tell me i'm going wrong or changes required solution. in advance.
how tried
activity_main:
<progressbar android:id="@+id/progressbar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_gravity="center_horizontal" android:visibility="invisible" /> <listview android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="fill_parent" > </listview>
mainactivity:
public class gettingalerts extends listactivity { // initialization ipaddress ipaddressobject = new ipaddress(); public static string getting_alerts_url = "http://" + ipaddress.ip_address.tostring() + "/myservices/alerts/alertservice.svc/gettingallalerts"; // tags public static string tag_name = "getallalertsresult"; public static string tag_alert_title = "alerttitle"; public static string tag_alert_description = "alertdescription"; public static string tag_alert_owner = "alertowner"; public static string tag_alert_deadline = "alertdeadline"; static string serv_response = ""; arraylist<alerts> alertslist; progressbar pg; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.alert_activity_list); pg = (progressbar) findviewbyid(r.id.progressbar1); // requestwindowfeature(window.feature_indeterminate_progress); // setprogressbarindeterminatevisibility(true); alertslist = new arraylist<alerts>(); listview lv = getlistview(); // setprogressbarindeterminatevisibility(false); new gettingalertslist().execute(); } private class gettingalertslist extends asynctask<void, void, void> { @override protected void doinbackground(void... params) { // todo auto-generated method stub // linearlayout linlaheaderprogress = (linearlayout) // findviewbyid(r.id.linlaheaderprogress); defaulthttpclient httpclient = new defaulthttpclient(); httpget httpget = new httpget(getting_alerts_url); httpresponse httpresponse = null; try { httpresponse = httpclient.execute(httpget); } catch (clientprotocolexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } httpentity httpentity = httpresponse.getentity(); try { serv_response = entityutils.tostring(httpentity); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } try { if (serv_response != null) { jsonobject jsonobj = new jsonobject(serv_response); jsonarray quiz = jsonobj.getjsonarray(tag_name); (int = 0; < quiz.length(); i++) { jsonobject c = quiz.getjsonobject(i); string alert_title = c.getstring(tag_alert_title); string alert_owner = c.getstring(tag_alert_owner); string alert_desc = c.getstring(tag_alert_description); string alert_dealdine = c.getstring(tag_alert_deadline); alerts alertobject = new alerts(); alertobject.setalerttitle(alert_title); alertobject.setalertdescription(alert_desc); alertobject.setalertdeadline(alert_dealdine); alertobject.setalertowner(alert_owner); alertslist.add(alertobject); } } } catch (jsonexception e) { // todo: handle exception e.printstacktrace(); } return null; } @override protected void onpostexecute(void result) { // todo auto-generated method stub super.onpostexecute(result); customalertlistadapter adapter = new customalertlistadapter( gettingalerts.this, alertslist); setlistadapter(adapter); pg.setvisibility(view.gone); } @override protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); pg.setvisibility(view.visible); } } }
image
as see progressbar @ top of activity. want progressbar in center
of activity before loading list.
try this..
remove android:layout_alignparenttop="true"
, android:layout_gravity="center_horizontal"
, add android:layout_centerinparent="true"
<relativelayout 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" > <progressbar android:id="@+id/progressbar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:visibility="invisible" /> <listview android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="fill_parent" > </listview> </relativelayout>
Comments
Post a Comment