Here is the code of my button activity, i managed to add a progressdialog so when the actvity sciencetechnology is loading its shows loading..only it isn't spinning so i'm wondering what im doing wrong, maby someone can look for my mistake here is the code:
package net.thinkbin;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
public class tutorial1 extends Activity{
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
Button share = (Button) findViewById(R.id.button2);
share.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("net.thinkbin.SHARE"));
overridePendingTransition(0, 0);
finish();
}
});
Button menu = (Button) findViewById(R.id.buttonhome);
menu.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
progressDialog = ProgressDialog.show(tutorial1.this, "", "Loading...");
Thread th = new Thread(new Runnable() {
public void run(){
startActivity(new Intent("net.thinkbin.MENU"));
overridePendingTransition(0, 0);
progressDialog.dismiss();
finish();
}
});
th.start();
}
});
Button culture = (Button) findViewById(R.id.button3);
culture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
progressDialog = ProgressDialog.show(tutorial1.this, "", "Loading...");
Thread th = new Thread(new Runnable() {
public void run(){
startActivity(new Intent("net.thinkbin.CULTURE"));
overridePendingTransition(0, 0);
progressDialog.dismiss();
finish();
}
});
th.start();
}
});
Button entertainment = (Button) findViewById(R.id.button4);
entertainment.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
progressDialog = ProgressDialog.show(tutorial1.this, "", "Loading...");
Thread th = new Thread(new Runnable() {
public void run(){
startActivity(new Intent("net.thinkbin.ENTERTAINMENT"));
overridePendingTransition(0, 0);
progressDialog.dismiss();
finish();
}
});
th.start();
}
});
Button philosophy = (Button) findViewById(R.id.button5);
philosophy.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
progressDialog = ProgressDialog.show(tutorial1.this, "", "Loading...");
Thread th = new Thread(new Runnable() {
public void run(){
startActivity(new Intent("net.thinkbin.PHILOSOPHY"));
overridePendingTransition(0, 0);
progressDialog.dismiss();
finish();
}
});
th.start();
}
});
Button sciencetechnology = (Button) findViewById(R.id.button6);
sciencetechnology.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
progressDialog = ProgressDialog.show(tutorial1.this, "", "Loading...");
Thread th = new Thread(new Runnable() {
public void run(){
startActivity(new Intent("net.thinkbin.SCIENCETECHNOLOGY"));
overridePendingTransition(0, 0);
progressDialog.dismiss();
finish();
}
});
th.start();
}
});
}
}
I can't be sure, but I've only ever seen Handler
or AsyncTask
used to run a separate thread. Either way, here is an example of using progressbar in android that works.
The way you are doing it currently is unconventional.
To get the spinning style action pre ICS you should call
showDialog(int);
and override
onCreateDialog(int);
to set the spinner style.
post ICS they have replaced all of this with the FragmentManager So you should use that to create the spinning style actions.
You have better to use AsynTask in Android rather than Thread.
Button sciencetechnology = (Button) findViewById(R.id.button6);
sciencetechnology.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
UrTask u=new UrTask ();
u..execute();
}
});
AsynTask
public class UrTask extends
AsyncTask<Void, Void, Void> {
ProgressDialog pDialog;
protected void onPreExecute() {
pDialog = new ProgressDialog(ActivityName.this);
pDialog.setMessage("Downloading Data...");
pDialog.setCancelable(false);
pDialog.show();
}
protected Void doInBackground(Void... unused) {
// Do ur work
return (null);
}
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
}
protected void onPostExecute(Void unused) {
pDialog.dismiss();
}
}