2012-04-04 115 views
0

這裏是我的按鈕活動的代碼,我設法添加一個progressdialog,所以當活動的科學技術正在加載其顯示loading ..只是它不旋轉,所以我想知道什麼即時通訊做錯了,莫比別人可以找我的錯誤這裏是代碼:ProgressDialog輪不旋轉

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


     } 
    }); 


} 

} 

回答

0

你現在這樣做的方式是非常規的。

爲了得到紡紗風格的動作預ICS你應該叫

showDialog(int); 

,並覆蓋

onCreateDialog(int); 

設置微調風格。

後ICS他們已經用FragmentManager代替了所有這些,所以你應該使用它來創建旋轉式的動作。

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


    } 
}); 

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

}