1

私は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.

したがって、これらの警告を解決するためにプロジェクトを「更新」したいと考えています。

Fragmentsと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;
    }
}

プロジェクトの早い段階で を作成しProgressDialogonPrepareDialog()メソッドで を呼び出しAsyncTaskてサーバーに接続し、データをダウンロードしました。その後onPostExecute、AsyncTask で を閉じてProgressDialog、新しいアクティビティを開始しました。onPrepareDialogしかし、廃止されたため、現在はそれを行うことができません。

Activy の 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);
}

これをどのように解決できますか?これを行う正しい方法は何ですか?私はこれに最適な、最も効率的なコードを書きたいと思っています。

ありがとう。

4

0 に答える 0