1

Im trying to bulid a clickable RecyclerView that will open a dialog. I cant figure out what wrong with my code, after I click the RV item the app carsh and this Eror is in the logcat:

android.util.AndroidRuntimeException: requestFeature() must be called before adding content
    at com.android.internal.policy.PhoneWindow.requestFeature(PhoneWindow.java:317)
    at com.android.internal.app.AlertController.installContent(AlertController.java:231)
    at android.app.AlertDialog.onCreate(AlertDialog.java:423)

The Adapter is suppose to create the CustomDialog when the user clicks an item from the RV. This is my Adapter relevant method:

@Override
public void onBindViewHolder(PartyViewHolder holder, final int position) {
    SingleParty party=partyList.get(position);
    String partyItemTitle= party.getPartyTitle()+ " at "+ party.getFourDigitTime()+ " in "+ party.getPlace();
    holder.partyDescription.setText(partyItemTitle);
    holder.linearLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ((PartiesActivity)context).showCustomDialog(partyList.get(position),position,partyList);
        }
    });
}

CustomDialog relevant code:

public class CustomDialog extends AppCompatDialogFragment {

private SingleParty editedParty;
private CustomDialogListener listener;
private RadioGroup eventPosted;
private RadioButton published,notPublished;
private EditText minAge, fourDigitTime, customerCost, originalCustomerCost, ticketsLeft, maxTickets, partyTitle, place, partyId, accountId, description;
private boolean selectedB,deleteB;
private String minAgeS, fourDigitTimeS, customerCostS, originalCustomerCostS, ticketsLeftS, maxTicketsS, partyTitleS, placeS, partyIdS, accountIdS, descriptionS;
ToggleButton deleteTB;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final View view = inflater.inflate(R.layout.custom_dialog, null);
    initializeVariables(view);
    builder.setView(view)
            .setTitle(R.string.dialog_title)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    selectedB=published.isChecked();
                    getStringDataFromDialog();
                    listener.applyTexts(selectedB,
                            deleteB,
                            minAgeS,
                    fourDigitTimeS,
                    customerCostS,
                    originalCustomerCostS,
                    ticketsLeftS,
                    maxTicketsS,
                    partyTitleS,
                    placeS,
                    partyIdS,
                    accountIdS,
                    descriptionS);
                }
            })
            // Add action buttons
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    //dont save changes
                }
            });
    AlertDialog alertDialog = builder.create();
    //gets the dialog to be rtl
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        alertDialog.getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
    }
    return alertDialog;
}

showCustomDialog:

 public void showCustomDialog(SingleParty editedParty, int position, ArrayList<SingleParty> listEdited){
    CustomDialog customDialog=new CustomDialog();
    customDialog.setEditedParty(editedParty);
    //check if he is super admin
    //super admin- delete waiting for published and edit/delete published one
    this.editedParty=editedParty;
    this.editedPosition=position;
    this.listEdited=listEdited;
    customDialog.show(getSupportFragmentManager(),"");
 //   customDialog.setDialogValues();
}

Thanks !

Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
Nakash.i
  • 371
  • 1
  • 3
  • 13
  • Have you see https://stackoverflow.com/a/28275485/3166697 ? – Dima Kozhevin Jun 29 '18 at 20:39
  • yes, but I don't have requestWindowFeature(Window.FEATURE_NO_TITLE); in my dialog's OnCreate. – Nakash.i Jun 29 '18 at 21:35
  • It calls in `public void setupDialog(Dialog dialog, int style)` of `AppCompatDialogFragment` after `onCreateDialog` – Dima Kozhevin Jun 29 '18 at 22:40
  • yes, but I cant change the onCreateDialog of AppCompatDialogFragment – Nakash.i Jun 30 '18 at 06:47
  • You can use `AppCompatDialog` instead of `AppCompatDialogFragment`. I suppose this action helps you to solve the problem but I'm not sure. – Dima Kozhevin Jun 30 '18 at 07:58
  • It's running after some changes, but now the dialog is not showing to the screen at all, the screen just gets gray, and after a click, it returns to normal(like there is a dialog, just without its box and details). – Nakash.i Jun 30 '18 at 08:29

0 Answers0