我试图用我的应用程序的进度条 - 在按钮的点击,应显示上有一个进度条部件新布局 - 我想下面的代码使用进度条
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Button:
Intent intent = new Intent(Welcome.this, progbar.class);
startActivity(intent);
break;
}
public class progbar extends Activity{
private ProgressBar prgbar;
private int prgStatus = 0;
private Handler mHandler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.lProgbar);
prgbar = (ProgressBar) findViewById(R.id.ReceiveUAI_prg);
// Start lengthy operation in a background thread
new Thread(new Runnable() {
public void run() {
while (prgStatus < 100) {
prgStatus += 2;
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
prgbar.setProgress(prgStatus);
}
});
}
}
}).start();
}
}
但是我的应用程序在点击按钮时被终止。
什么是堆栈跟踪的细节? – Mudassir 2011-03-29 10:19:03
堆栈跟踪意味着logcat或控制台? – bhabs 2011-03-29 10:41:45
是的,logcat。它显示了异常的细节。 – Mudassir 2011-03-29 10:44:58