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?
To create a DialogFragment , first create a class that extends DialogFragment , and override onCreateDialog() , as shown in the following example. Similar to how onCreateView() should create a root View in an ordinary fragment, onCreateDialog() should create a Dialog to display as part of the DialogFragment .
This class was deprecated in API level 28.
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
for approved namings use About instead of about its just
new About().show(getSupportFragmentManager(),"about");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With