0

加载进度条后无法启动新活动。我卡在进度条上,不知道应该把新活动放在哪里。我的问题有什么解决办法吗?

ProgressBar myProgressBar;
int myProgress = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    myProgressBar=(ProgressBar)findViewById(R.id.progressbar_Horizontal);

    new Thread(myThread).start();
}

private Runnable myThread = new Runnable(){

    public void run() {
        // TODO Auto-generated method stub
        while (myProgress<100){
            try{
                myHandle.sendMessage(myHandle.obtainMessage());
                Thread.sleep(50);
            }
            catch(Throwable t){

            }
        }
    }
    Handler myHandle = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            myProgress++;
            myProgressBar.setProgress(myProgress);
        }
    };
};

}

4

2 回答 2

2

请将此添加到您的按钮单击事件中。

            progressDialog = ProgressDialog.show(this, "", "Loading...");
            new Thread() {

                public void run() {

                    Intent ddIntent = new Intent(
                            MainActivity.this, MainWall.class);
                    startActivity(ddIntent);
                    progressDialog.dismiss();
                }

            }.start();
于 2012-05-10T04:34:46.783 回答
0
public void run() {
    //don't hard code things, use a constant for max progress value
    while ( myProgress<MAX_PROGRESS ){
        try{
            myHandle.sendMessage(myHandle.obtainMessage());
            //same
            Thread.sleep( SLEEP_TIME );
        } catch(Exception ex){
          //never live an empty catch statement, you are missing exceptions and
          //can't correct them
          Log.e( "MyCurrentClass", "Error during async data processing",e );
        }//catch
    }//while
    //start new activity here
    startActivity( MyClass.this, NewActivity.class );
}//met
于 2012-05-08T21:39:35.137 回答