ProgressDialog轮不旋转

时间:2012-04-04 22:40:03

标签: android button android-activity progressdialog

这是我的按钮活动的代码,我设法添加了一个progressdialog所以当actvity sciencetechnology正在加载它的节目加载时...它不会旋转所以我想知道我做错了什么,maby有人可以看看因为我的错误是代码:

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();


        }
    });


}

}

3 个答案:

答案 0 :(得分:0)

我无法确定,但我只看到HandlerAsyncTask用于运行单独的线程。无论哪种方式,这里都是example of using progressbar in android that works

答案 1 :(得分:0)

你目前的做法是非常规的。

要获得ICS前的旋转式动作,您应该致电

showDialog(int);

并覆盖

onCreateDialog(int);

设置微调器样式。

发布ICS后,他们用FragmentManager替换了所有这些,所以你应该用它来创建旋转式动作。

答案 2 :(得分:0)

最好在Android中使用AsyncTask而不是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();


    }
});

AsyncTask

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();
    }

}