내 사용자 정의 대화 상자에 구하는 데 오랜 시간이 걸리는 목록이 있습니다. 그래서 AsyncTask를 사용하여 onPrepareDialog에서 시작된 별도의 스레드에로드합니다. AsyncTask.execute를 호출하기 전에 ProgressDialog를 호출합니다. 문제는 대화 상자가 처음으로 호출 될 때 (onCreateDialog가 호출 될 때) ProgressDialog가 내 (빈) 대화 상자 뒤에 표시된다는 것입니다. hr에서 ProgressDialog를 어떻게 표시합니까? 대화 상자가 사라지고 다시 표시되면 표시 순서가 정확합니다.ProgressDialog가 다른 대화 상자 뒤에 표시됩니다.
public class MyActivity extends Activity {
FileSelectDlg fileSelectDlg = null;
LayoutInflater inflater;
ArrayList<String> fileList;
@Override
public void onCreate(Bundle savedInstanceState) {
inflater = LayoutInflater.from(this);
}
@Override
protected Dialog onCreateDialog(int id)
{
fileSelectDlg = new FileSelectDlg(this);
return fileSelectDlg;
}
@Override
protected synchronized void onPrepareDialog(int id, Dialog dialog) {
fileSelectDlg.update_dlg_view(-1);
}
public class FileSelectDlg extends Dialog {
private Context context;
private BaseAdapter adapter;
public FileSelectDlg(Context context) {
super(context);
this.context = context;
View content = inflater.inflate(R.layout.file_select, null);
setContentView(content);
adapter = new BaseAdapter() {
@Override
public int getCount() {
if(fileList != null)
return fileList.size();
return 0;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView;
if (convertView == null) {
convertView = inflater.inflate(R.layout.file_select_item, null);
textView = (TextView) convertView.findViewById(R.id.item_text);
convertView.setTag(textView);
} else {
textView = (TextView)convertView.getTag();
}
if(fileList != null) {
textView.setText(fileList.get(position));
}
return convertView;
}
};
ListView listView = (ListView)findViewById(R.id.list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int clicked, long id) {
update_dlg_view(clicked);
}
});
}
public void update_dlg_view(int clicked) {
int option = option_get_list;
String item = null;
if(clicked >= 0) {
item = fileList.get(clicked);
fileSelector.setDir(item);
}
final ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setMessage("wait...");
progressDialog.setCancelable(false);
progressDialog.show();
new AsyncTask<Integer, Integer, Long>() {
protected Long doInBackground(Integer... _option) {
long option = _option[0];
fileList = fileSelector.getList();
return option;
}
@Override
protected void onPostExecute(Long option) {
progressDialog.dismiss();
FileSelectDlg.this.setTitle(fileSelector.getCurrentPath());
adapter.notifyDataSetChanged();
}
}.execute(option);
}
}
당신은 여기에 코드의 조각을 붙여주십시오 수 있습니다. –