我想在从服务器下载时使用进度条,实际上我正在使用progressDialog但是如果我使用progressBar而不是progressDialog将会很好看。我有以下代码用于进度对话框。
public class FeaturedData extends AsyncTask<Void, Void, Void> {
Home home;
ProgressDialog dialog = null;
public FeaturedData(Home home) {
// TODO Auto-generated constructor stub
this.home = home;
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
//calling here method
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialog.dismiss();
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog = ProgressDialog.show(home, "", "", true);
}
答案 0 :(得分:3)
根据您的以下评论:
实际上我想以编程方式执行此操作,不希望在xml中声明。
=&GT;我建议你把它放在XMl布局中。
progressBar.setVisibility(View.VISIBLE)
progressBar.setVisibility(View.GONE)