0

The class below is in a file Test.java and I want to call it from the function of public class Test. Now i dont know how to access the function to show the alertdialog. I mean how to access onCreateDialog(Bundle savedInstanceState) of the class below , from another method?

the code below is copied from this source

  class MyCustomDialog extends DialogFragment{
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(inflater.inflate(R.layout.notification_list_layout, null))
        // Add action buttons
               .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // sign in the user ...
                   }
               })
               .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       MyCustomDialog.this.getDialog().cancel();
                   }
               });      
        return builder.create();
    }

}

I want something like this enter image description here

magicgb
  • 58
  • 7
  • I'm stuck here. Just don't know how to get access to it – magicgb Jan 17 '13 at 06:33
  • Not sure abt your question, but http://stackoverflow.com/a/8311800/1777090 might help – MysticMagicϡ Jan 17 '13 at 06:34
  • I don't know how to access onCreateDialog(Bundle savedInstanceState) of class MyCustomDialog so that i can popup a alert box as defined above – magicgb Jan 17 '13 at 06:38
  • Ok. Refer to this. http://arusahni.net/blog/2012/01/implementing-custom-alert-dialogfragments/ . There is method newInstance() in custom dialogfragment class. So you will be able to use it, I think – MysticMagicϡ Jan 17 '13 at 06:40
  • Not clear whats your question can you please post me what do you want to display in the custom dialog. – Abhijit Chakra Jan 17 '13 at 07:00
  • thanks but i couldnt help myself – magicgb Jan 17 '13 at 07:01
  • hi.. you want to create your own layout as alert dialog ? – itsrajesh4uguys Jan 17 '13 at 07:22
  • yes i want to create my own layout .. i see the documentation but i couldnt help myself how to call it. I have uploaded the image in my question - cropped from http://developer.android.com/guide/topics/ui/dialogs.html. Please follow the link ans you will see same image. I want exactly that – magicgb Jan 17 '13 at 11:19
  • MyCustomDialog custDialog = new MyCustomDialog(); custDialog.show(manager, tag) ; what to put in 'manager' – magicgb Jan 17 '13 at 11:35
  • @ itsrajesh4uguys yes i want ot create my own custom dialogbox – magicgb Jan 17 '13 at 11:57

2 Answers2

3
MyCustomDialog custDialog = new MyCustomDialog();
custDialog.show(custDialog.getFragmentManager(), "Info"); 
GaurabDahal
  • 876
  • 6
  • 16
0

I think this should work MyCustomDialog custDialog = new MyCustomDialog(); custDialog.show(manager, tag)

Shraddha Shravagi
  • 1,096
  • 1
  • 9
  • 22