Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have dialog fragment. I have intention to use this fragment in activity and dialog. And I override onCreateDialog and onCreateView method. here is coding.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.interval_time_popup, null);
        setup(view, false);
        return view;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View view = getActivity().getLayoutInflater().inflate(R.layout.interval_time_popup, null);

        builder.setTitle("Interval Time");
        builder.setView(view);
        setup(view, true);
        builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                listener.setOnIntervalTime(hourNp.getValue(), minNp.getValue());
                dismiss();
            }
        });
        builder.setNegativeButton("Cancel", new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dismiss();
            }
        });
        return builder.create();
    }

I use this fragment in the activity class like that.

           SelectTimeIntervalDialogFragment fragment = new SelectTimeIntervalDialogFragment();
            fragment.setHrMin(hr, min);
            Bundle args = new Bundle();

            FragmentTransaction t = getSupportFragmentManager().beginTransaction();
            t.replace(R.id.shift_period_interval_layout, fragment);
            t.commit();

I call it from another activity like that.

            if((getResources().getConfiguration().screenLayout &
                            Configuration.SCREENLAYOUT_SIZE_NORMAL) ==
                            Configuration.SCREENLAYOUT_SIZE_NORMAL){
                        Intent intent = new Intent(ShiftPeriodActivity.this, SelectIntervalActivity.class);
                        intent.putExtra("intervalHr", speriod.intervalHr);
                        intent.putExtra("intervalMin", speriod.intervalMin);
                        startActivityForResult(intent, 1);
                    } else {
                        FragmentManager fm = getSupportFragmentManager();
                        intervalDialog = new SelectTimeIntervalDialogFragment();
                        intervalDialog.setHrMin(speriod.intervalHr, speriod.intervalMin);
                        intervalDialog.show(fm, "interval_fragment");
                    }

I have two conditions. When the screen size is normal, it call activity which include fragment dialog. Otherwise, it call the popup dialog. I got the exception when it call the popup dialog. It said requestFeature() must be called before adding content. Can I use like this? I would like to know how to overcome this.

Thanks.

share|improve this question
you should be called first requestFeature before the setcontentView() – sunil Jul 5 at 11:36
Whether your problem solved?? – Subburaj Jul 6 at 7:26

1 Answer

i think you are using requestWindowFeature(); at on create

use it before setContentView(R.layout.activity);

share|improve this answer
I got the exception when I call the popup dialog. – user1156041 Jul 6 at 6:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.