0

这是我的按钮活动的代码,我设法添加了一个进度对话框,所以当活动科学技术正在加载它的显示加载时......只是它没有旋转,所以我想知道我做错了什么,也许有人可以寻找我的错误这是代码:

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


        }
    });


}

}
4

3 回答 3

0

我不能确定,但​​我只见过HandlerAsyncTask曾经运行过一个单独的线程。无论哪种方式,这是一个在 android 中使用进度条的示例

于 2012-04-04T22:52:02.700 回答
0

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

要获得 ICS 之前的旋转式动作,您应该调用

showDialog(int);

并覆盖

onCreateDialog(int);

设置微调器样式。

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

于 2012-04-05T13:09:24.637 回答
0

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


    }
});

异步任务

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

}
于 2013-03-12T06:41:31.600 回答