Skip to content
Advertisement

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 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?

Advertisement

Answer

for approved namings use About instead of about its just

new About().show(getSupportFragmentManager(),"about");
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement