上の非常に奇妙な行動私はアンドロように私のコードを更新しましたが、私に書いた:アンドロイド - プログレスバー
public class ZiiziiActivity extends Activity {
ProgressDialog pd;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pd = new ProgressDialog(ZiiziiActivity.this);
final Handler handler = new Handler()
{
public void handleMessage(Message msg)
{
if(msg.what==0)
{
pd.dismiss();
}
}
};
Button end = (Button) findViewById(R.id.button2);
end.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setMessage("Working...");
pd.setIndeterminate(true);
pd.setCancelable(false);
pd.show();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int i=0;i<1000000;i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //To denote a delay in background processing
}
handler.sendEmptyMessage(0);
}
}); t.start();
}
});
}
}
しかし、進行開始を、それは決して終わりません。
何が間違っていますか?
forループの制限を減らします。私のような何か<10 ..とチェック –
ありがとう!!!!その作品!!!! – Gold
ループの代わりに私の関数を呼び出そうとしています - for(i ......)とエラーが発生しました:java.lang.RuntimeException:Looper.prepare()を呼び出さなかったスレッド内でハンドラを作成できません – Gold