The method show(FragmentManager, String) in the type DialogFragment is not appli

2274 ワード

The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentManager, String)
 
	public static class MyDialogFragment extends DialogFragment {

		AlertDialog dialog = null;

		@Override
		public Dialog onCreateDialog(Bundle savedInstanceState) {

			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			// Get the layout inflater
			LayoutInflater inflater = getActivity().getLayoutInflater();

			View container = inflater.inflate(R.layout.dialog_layout, null);
			Button btnIPCall = (Button) container
					.findViewById(R.id.btn_ip_call);
			btnIPCall.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					if (dialog != null)
						dialog.dismiss();
				}
			});
			Button btnNormalCall = (Button) container
					.findViewById(R.id.btn_normal_call);
			btnNormalCall.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					if (dialog != null)
						dialog.dismiss();

				}
			});

			// Inflate and set the layout for the dialog
			// Pass null as the parent view because its going in the dialog
			// layout
			builder.setView(container);
			dialog = builder.create();
			return dialog;
		}

	}

 
開発中に上記のエラー(赤いフォント)に遭遇し、長い間探していました.理由は次のとおりです.
import android.support.v4.app.DialogFragment;

インポートに変更
import android.app.DialogFragment;

普通です.
 
または
つかむ
public class MainActivity extends Activity {

に改心
public class MainActivity extends FragmentActivity {

 
 
もちろん他の原因による可能性もありますので、試してみてください
As you're using android.support.v4.app.DialogFragment, you should pass to show() an instance of android.support.v4.app.FragmentManager which can be queried using an getSupportFragmentManager() call. Hope this helps.