Android 如何更改DialogFragments的显示/删除对话框和onPrepareDialog
我在做一个Android项目。我需要使用Android 1.6或更高版本 我的项目正在运行,但现在它向我显示了一些关于对话框的警告,如Android 如何更改DialogFragments的显示/删除对话框和onPrepareDialog,android,dialog,android-fragments,Android,Dialog,Android Fragments,我在做一个Android项目。我需要使用Android 1.6或更高版本 我的项目正在运行,但现在它向我显示了一些关于对话框的警告,如 "The method dismissDialog(int) from the type Activity is deprecated" "The method showDialog(int) from the type Activity is deprecated", etc. 所以我想“更新”我的项目来解决这些警告 我已经阅读并制作了一些测试项目来了解片段
"The method dismissDialog(int) from the type Activity is deprecated"
"The method showDialog(int) from the type Activity is deprecated", etc.
所以我想“更新”我的项目来解决这些警告
我已经阅读并制作了一些测试项目来了解片段和DialogFragment。
我已经创建了自己的ProgressDialog,我想在我的实际项目中使用它,但我有一些问题
public class MyProgressDialog extends DialogFragment {
public MyProgressDialog(){
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
ProgressDialog dialog = new ProgressDialog(context);
Resources resources = context.getResources();
String message = resources.getText(R.string.wait).toString();
dialog.setMessage(message);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
return dialog;
}
}
在我的项目早期,我创建了ProgressDialog
,然后在onPrepareDialog()
方法中,我调用了AsyncTask
来连接服务器、下载数据等。然后在AsyncTask的onPostExecute
中,我取消了ProgressDialog
并开始了新的活动。但现在我不能这样做,因为onPrepareDialog
已被弃用
在活动的onPrepareDialog上调用ActionAsyncTask
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch(id){
case Constants.PROGRESS_DIALOG:
new ActionAsyncTask().execute();
break;
}
}
ActionAsyncTask的onPostExecute
@Override
protected void onPostExecute(Integer result) {
dismissDialog(Constants.PROGRESS_DIALOG);
}
如何解决这个问题?正确的方法是什么?我想为此编写最好的代码,最高效的代码
谢谢