Monday, May 16, 2016

User Dialog Fragment


Here are some important learnings for displaying a user dialog fragment. Steps to create:

  1. Create a new layout file for the dialog.
  2. Create a new Java class to inflate the fragment. This should extend the Android system DialogFragment class.
  3. Create reference in the main activity to inflate the dialog
To accomplish this, I simply created a new method in MainActivity.java called "showDialog()".

public void showDialog(View v){
        FragmentManager manager = getFragmentManager();
        FragmentDialog addDialog = new FragmentDialog();
        addDialog.show(manager, "addDialog");
}

You can see I am making use of two new objects:

  1. FragmentDialog --> This is the class I created to inflate the new xml layout
  2. FragmentManager --> Android system object used as an interface for dealing with fragments

Helpful resources:

No comments:

Post a Comment