Reputation: 551
here is the code, currently the progressdialog is shown if user click the button, and the 'ring' is not spinning. but if i paste the progreedialog's code under onCreate, the 'ring' will spin once the screen is loaded. help me find where went wrong..
StaffChoice class:
public class StaffChoice extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.staffchoices);
}
public void onClickCategory(final View view)
{
final ProgressDialog progress=ProgressDialog.show(this, "Please wait", "Loading ...", true);
new Thread()
{
public void run()
{
Intent intent = new Intent(view.getContext(), Category.class);
startActivity(intent);
progress.dismiss();
}
}.start();
}
}
onCreate in Category class:
super.onCreate(savedInstanceState);
setContentView(R.layout.category);
final ListView lvCategory = (ListView) findViewById(R.id.lvCategory);
SoapObject Request = new SoapObject (NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
try
{
aht.call(SOAP_ACTION, soapEnvelope);
SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
final String[] strCategory = new String[resultString.getPropertyCount()];
for(int i =0; i<resultString.getPropertyCount(); i++)
{
SoapObject array = (SoapObject) resultString .getProperty(i);
strCategory[i] = array.getProperty(0).toString(); //get category
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strCategory);
lvCategory.setAdapter(adapter);
lvCategory.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, final View arg1, int arg2, long arg3) {
Intent intent = new Intent(arg1.getContext(), CategoryGames.class);
startActivity(intent);
}
});
}
catch(Exception e)
{
String[] items = { "No Internet Connection, Please try again" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
lvCategory.setAdapter(adapter);
}
Upvotes: 0
Views: 1816
Reputation: 551
instead of Thread, i use AsyncTask at the new intent
protected void onCreate(Bundle savedInstanceState)
{
new loadPage().execute(null, null, null);
}
public class loadPage extends AsyncTask<String, Integer, Void> {
private ProgressDialog pdia;
@Override
protected void onPreExecute(){
super.onPreExecute();
pdia = new ProgressDialog(AppDetails.this);
pdia.setMessage("Loading...");
pdia.show();
}
@Override
protected Void doInBackground(String... arg0) {
// TODO Auto-generated method stub
}
@Override
protected void onPostExecute(Void unused) {
pdia.dismiss();
}
}
Upvotes: 1
Reputation: 40416
you have to put Task or Time in thread while thread is running ,progress Dialog is showing,But when Task/Time is complete progressDialog dismiss.
Its better to use AsynTask in Android rather than Thread.
new Thread()
{
public void run()
{
try{
Thread.sleep(10*1000); //10 seconds
}catch(Exception e){
}
handler.sendEmptyMessage(0);
}
}.start();
Upvotes: 1