Inflating a view for a AlertDialog
I’m in the process of updating Jumpy not only to give it some polish, but also learn more of the ins and outs of the Android Market marketing capabilities…hopefully I’ll also figure out how to insert advertising and possibly make a little extra cash.
Anywho, as I’ve been updating some of the code, I came across my custom AboutDialog and decided it needed to go into an AlertDialog instead. By using the code below, I was able to use the same layout resource of the AboutDialog (removing a couple widgets) and fully utilizing the AlertDialog by instantiating a View via the LayoutInflater and setting it into the AlertDialog.
private void openAboutDialog()
{
AlertDialog.Builder dialog = new AlertDialog.Builder( this );
dialog.setView( getLayoutInflater().inflate( R.layout.about_layout, null ) );
dialog.setTitle( getString( R.string.about_jumpy_title ) );
dialog.setPositiveButton( getString( R.string.done ), null );
dialog.show();
}
It’s really nice that with the getLayoutInflater().inflate call you only have to supply the resource since the root ViewGroup is optional. Now I’m able to get rid of the AboutDialog class and remove 50 some odd lines of code from the applications.
