我试图在填充布局时显示进度对话框:
编辑(这里是代码):
public class CalendarMonth extends Activity {
private ProgressDialog mDialog;
private int mMonth = 0;
private int mYear = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar_m);
filterData();
}
private void filterData() {
mDialog = ProgressDialog.show(this, "Loading calendar",
"Please wait...", true, true);
mDialog.setCancelable(false);
mDialog.show();
new GenerateMonth().execute();
}
class GenerateMonth extends AsyncTask {
protected Object doInBackground(Object... arg0) {
generateMonth();
return true;
}
protected void onPostExecute(Object result) {
mDialog.dismiss();
}
private void generateMonth() {
mCalendar = new CalendarInstance(mMonth, mYear);
mMonth = this.mCalendar.getSelectedMonth();
mYear = this.mCalendar.getSelectedYear();
TextView monthName = (TextView) findViewById(R.id.monthName);
monthName.setText(mCalendar.getMonthAndYearAsString());
Button monthPrevious = (Button) findViewById(R.id.monthPrevious);
monthPrevious.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int month = mMonth - 1;
int year = mYear;
if (mMonth == 1) {
month = 12;
year = mYear - 1;
}
mMonth = month;
mYear = year;
filterData();
}
});
Button monthNext = (Button) findViewById(R.id.monthNext);
monthNext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int month = mMonth + 1;
int year = mYear;
if (mMonth == 12) {
month = 1;
year = mYear + 1;
}
mMonth = month;
mYear = year;
filterData();
}
});
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setNumColumns(7);
gridview.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
gridview.setBackgroundColor(Color.BLACK);
gridview.setAdapter(new CalendarMonthAdapter(this, mMonth, mYear));
}
@Override
protected void onResume() {
super.onResume();
filterData();
}
}