PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 26, 2022

[FIXED] How to Create a create_dialog() Method in Android Studio in which you can pass the name of the Dialog Name you want to create with the Method

 October 26, 2022     android-studio, java, oop     No comments   

Issue

i want to create a Method which creates a dialog in Android Studio, but i also want to pass in the name of the Dialog which should be used as the Dialogname. Until now i use the following metgod to create Dialogs:

    Dialog DialogName = new Dialog(context);
    //Parameters of the Dialog
    //Parameters of the Dialog
    //Parameters of the Dialog
    //Parameters of the Dialog
    //Parameters of the Dialog
    DialogName.show();

But since the parameteres are the same everytime but the names of the dialoges change i just want to use a method to handle rest for me something like

    create_dialog_method("my_new_Dialog",MainActivity.this);
    //Some Other Code
    my_new_Dialog.dismiss();

The method i want to declare outside of onCreate Method but within AppCompat would be something like:

    private void create_dialog_method(String DialogName,Context context) {
    Dialog DialogName = new Dialog (context);
    //Other parameters which are the same for every dialog
    //Other parameters which are the same for every dialog
    //Other parameters which are the same for every dialog
    //Other parameters which are the same for every dialog
    //Other parameters which are the same for every dialog
    DialogName.show();
}

Thanks in Regards for any help


Solution

The easiest approach to create custom dialogs is to create a new class named 'mycustomdialog' whşch extends the normal 'Dialog' Class from AppCompat in order to have same functionality. Then for parameters like width, length..... And all the parameters which should stay fixed for each dialog, I would set these properties within the 'mycustomdialog' Class and add a String parameter to the constructor of rhe class to set the different names.



Answered By - abdussamed17
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing