自定义Dialong中包含了 ProgressBar 。 在调用Dialog的时候,如何控制 进度条的进度 ?public void onClick(DialogInterface dialog, int which) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.sync_dialog,
(ViewGroup) findViewById(R.id.dialog));
AlertDialog.Builder sync_dialog = new Builder(HomeActivity.this);
sync_dialog.setIcon(android.R.drawable.ic_dialog_info);
sync_dialog.setTitle("号簿更新");
sync_dialog.setView(layout);
sync_dialog.setNegativeButton("取消", null); System.out.println("progressbar set value");
final ProgressBar sync_progressbar = (ProgressBar) findViewById(R.id.progressbar); sync_dialog.show(); new Thread() {
int m_count = 0; public void run() { try {
while (m_count <= 100) {
System.out.println(m_count);
sync_progressbar.setProgress(m_count + 10);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
// timer.schedule(task, 1000); }
});
我这样实现的时候 出现空指针错误, sync_progressbar 为空。 求大侠们 给提示 给代码啊
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.sync_dialog,
(ViewGroup) findViewById(R.id.dialog));
AlertDialog.Builder sync_dialog = new Builder(HomeActivity.this);
sync_dialog.setIcon(android.R.drawable.ic_dialog_info);
sync_dialog.setTitle("号簿更新");
sync_dialog.setView(layout);
sync_dialog.setNegativeButton("取消", null); System.out.println("progressbar set value");
final ProgressBar sync_progressbar = (ProgressBar) findViewById(R.id.progressbar); sync_dialog.show(); new Thread() {
int m_count = 0; public void run() { try {
while (m_count <= 100) {
System.out.println(m_count);
sync_progressbar.setProgress(m_count + 10);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
// timer.schedule(task, 1000); }
});
我这样实现的时候 出现空指针错误, sync_progressbar 为空。 求大侠们 给提示 给代码啊
感谢楼上的回答 , 发现问题了
改成如下:
final ProgressBar sync_progressbar = (ProgressBar) layout.findViewById(R.id.progressbar);结贴给分