Reputation: 67
Getting
Error:(192, 23) error: no suitable method found for show(ActionBar,String)
method DialogFragment.show(FragmentTransaction,String) is not applicable
(actual argument ActionBar cannot be converted to FragmentTransaction by method invocation conversion)
method DialogFragment.show(FragmentManager,String) is not applicable
(actual argument ActionBar cannot be converted to FragmentManager by method invocation conversion)
when trying to create a custom dialog box, getting error in dialog.show(getSupportActionBar(), "dialog");
this code.
Here is my brief code:
public boolean onPrepareOptionsMenu(android.view.Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
Button settBtn = (Button) findViewById(R.id.action_settings);
settBtn.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
CustomDialogFragment dialog = new CustomDialogFragment();
dialog.show(getSupportActionBar(), "dialog");
}
});
return super.onPrepareOptionsMenu(menu);
}
public class CustomDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getActivity());
dialog.getWindow().getAttributes().windowAnimations = R.style.Animation_CustomDialog;
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_custom);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setCanceledOnTouchOutside(false);
TextView message = (TextView) dialog.findViewById(R.id.message);
message.setText(">>>>>>>");
dialog.findViewById(R.id.positive_button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});
dialog.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});
return dialog;
}
}
Please help me to resolve this.Thanks in advance.....
Upvotes: 0
Views: 822
Reputation: 67
Solved by using FragmentManager
FragmentManager fm;
fm= getFragmentManager();
CustomDialogFragment dialog = new CustomDialogFragment();
dialog.show(fm , "dialog");
Upvotes: 2
Reputation: 6834
DialogFragment fragment = new DialogFragment();
fragment.show(getSupportFragmentManager(), "dialog");
Upvotes: 0