Categories
discuss

Start DialogFragment from Activity

I’m learning Android programming with IntelliJ right now and got a little problem. I’ve got an Activity which looks like this: public class example2 extends Activity { …some code… public …

I’m learning Android programming with IntelliJ right now and got a little problem.

I’ve got an Activity which looks like this:

public class example2 extends Activity {
    ...some code...
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.optExit:
                finish();
                return true;
            case R.id.optSettings:
                Intent sintent = new Intent(this, settings.class);
                startActivity(esintent);
                return true;
            case R.id.optAbout:
                //need to start the fragmentdialog

        }
        return true;
    }
    ...some code...
}

And this is how my DialogFragment looks like

public class about extends DialogFragment {

    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
        b.setTitle("About");
        b.setMessage("some text");
        b.setCancelable(false);
        b.setPositiveButton("OK", null);
        return b.create();
    }
}

I’ve tried nearly everything, creating a new instance and start the method, using FragmentManager, which i wasn’t able to use. What should I do?

Answer

for approved namings use About instead of about its just

new About().show(getSupportFragmentManager(),"about");
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..