添加内容之前必须先调用requestFeature()-RecyclerView

时间:2018-06-29 19:50:30

标签: java android android-recyclerview alertdialog

我正在尝试构建可点击的RecyclerView,这将打开一个对话框。 在单击RV项目后,我无法弄清楚我的代码有什么问题,该错误会出现在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)

假设用户单击RV中的某个项目时,适配器将创建CustomDialog。 这是我的适配器相关方法:

@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相关代码:

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();
}

谢谢!

0 个答案:

没有答案