ITeye博客

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

xinanadu · 2013-04-17 16:06 · android · 移动开发 · Markdown

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.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。