• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps May be a simple task, but having no luck understanding it, want progressbar on load

cubangt

Newbie
I have a menu within my app that takes you to a view that is call a web service to return a list of records. This works, but depending on connection can take 1 to 5 secs to return, so i would like to add a progress bar to this process so the user knows that its working on loading / returning the data.

All the examples i have found are great, but have hard coded data and calculations to mimic the progress spinner as if it was processing data.

But coming from C# .net programming to android apps, still trying to grasp the logic that makes this all work..

I have successfully built my app to submit data via email as well as webservice, and added menu that returns the data in the database.

Just having trouble placing the progress bar around my event so taht it shows when the page is loading and goes away when page loads..

here is my code for the "HistoryActivity.java" file, some lines are commented out and some arent that really should, but thats only for my testing and debugging..

Code:
[SIZE=2]
[LEFT][/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/** Called when the activity is first created. */[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onCreate(Bundle savedInstanceState) {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);

[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f9fbf][SIZE=2][COLOR=#7f9fbf]TODO[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated method stub[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);
TextView textView = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TextView([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
setContentView(textView);
textView.setMovementMethod([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ScrollingMovementMethod());

StrictMode.[I]setThreadPolicy[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] StrictMode.ThreadPolicy.Builder() 
.detectDiskReads() 
.detectDiskWrites() 
.detectNetwork() 
.penaltyLog() 
.build());

SoapObject request = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SoapObject([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]WSDL_TARGET_NAMESPACE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]METHOD_NAME[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);

SoapSerializationEnvelope envelope = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SoapSerializationEnvelope(SoapEnvelope.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]VER11[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
envelope.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dotNet[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];

envelope.setOutputSoapObject(request);

HttpTransportSE httpTransport = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] HttpTransportSE([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]URL[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/LEFT]
[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]{ 
httpTransport.call([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SOAP_ACTION[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], envelope);

[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//SoapPrimitive response = (SoapPrimitive)envelope.getResponse();[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
SoapObject response = (SoapObject)envelope.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]bodyIn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](response != [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
{ 
SoapObject nameResult = (SoapObject) response.getProperty(0);

SoapObject serviceRecords = (SoapObject) nameResult.getProperty(1); 

[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Returns all records in table[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]SoapObject dar = (SoapObject) serviceRecords.getProperty(0);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] recCount = dar.getPropertyCount();
textView.setText([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Soap Response:\n\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + dar.toString() + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"\n\nRecord Count: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + recCount);
StringBuilder sb = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] StringBuilder();

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]for[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i=0;i<recCount;i++)
{
SoapObject suvas = (SoapObject) dar.getProperty(i);
String ex = suvas.getProperty([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ep"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).toString();
String sd = suvas.getProperty([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"sd"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).toString();
String dp = suvas.getProperty([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"dp"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).toString();
sb.append([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Service Date: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + sd + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Expected Payment: $"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + ex + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Date Paid: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + dp + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"\n\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}
textView.setText(sb.toString());
}
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (Exception exception)
{
textView.setText(exception.toString());
} [/LEFT]
}
[/SIZE]
 
Since your Web service is processing everything and returning it all at once instead of reterning it in increments, you will need to use an indeterminate progress bar (a circular spinner that simply shows the user that something is currently happening that they must wsit for)
 
thats all im looking for.. just not sure how to implement in my setup..
can you provide an example or even links to something that would work in my case.
 
Back
Top Bottom