Android Question Native Input Dialogs Android (No B4XDialogs)

Mike1970

Well-Known Member
Licensed User
Hi everyone, how can implement the native input dialogs of Android in my app?
i found this code here, but i don't know how to convert it:

B4X:
private void showForgotDialog(Context c) {
        final EditText taskEditText = new EditText(c);
        AlertDialog dialog = new AlertDialog.Builder(c)
                .setTitle("Forgot Password")
                .setMessage("Enter your mobile number?")
                .setView(taskEditText)
                .setPositiveButton("Reset", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String task = String.valueOf(taskEditText.getText());
                    }
                })
                .setNegativeButton("Cancel", null)
                .create();
        dialog.show();
    }

I need something like so:
WooAe.png


I tried to use B4XDialogs, but to me seemed unreliable... if i've a edtitext in the customlayout, the IME stop working, so i can't manage the layout when the keyboard appears.
Even if the ".PutAtTop" property was on TRUE, the dialog does not show on top of everything, but compenetrate with my otherpanels etc... So.. them are causing me waste of time...
example:
example-min.jpg

as you can see the msgbox is between the panel i use for preview the camera, and many buttons/imageview...
at the moment i dont' rely on them..

i need only an edittext in a msgbox 😂.. how can i implement the native alert dialog?


Thanks in advance
 

Cableguy

Expert
Licensed User
how can I find them?

he uses natives dialogs?

Just search for custom view dialog...

A custom view is basically the mix of 2 or more views to achieve a "missing" behaviour in B4X...
The one you are aiming can be achieve by creating a customviem and add a Label to display the warning and an inputTextView to enter the text and a couple of buttons for the actions.
CustomViews are VERY powerfull and easy to implement.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Have you tried hanging the elevation setting in your dialog?
you mean in the layout I use for the dialog?
no, and the reason is because I suppose that the ".PutAtTop" is a functioning method.

however, I can't take in consideration the elevation of all the elements in my app, since I can spawn a dialog potentially in every Activity... this should be the job of a dialog (or popup), it is the reason why it exist: provide a UI to the user to show an important thing, over the top of everything else is less important.

This is the reason why I wish to use the native option. because it is managed from the OS.

however that is not the only problem I had, the second problem is that, I want the dialog centered in the screen.. but when give the focus to the edit text, and the keyboard opens up, it covers the editext, and I don't know why, the ime_HeightChanged does not fires anymore... so.. I prefer not to struggling only to use a B4x thing, at the moment :(
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Just to get you started....
For completness. i tried to use the template, just to be sure that is not a problem of my layout.
I literally copy/paste the sub in the example, and initialized the "dialog".
Same result, the popup is between my panels, like in the screenshot i posted :(
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Elevation will set the order between childs of the same parent!
Read Google guidelines for elevation and you will see that it is quite usefull


Elevation - Material Design

Thanks for linking!
Actually i know what is elevation, i use multiple levels of elevation in my app. in some case just to get a good shadow.

what i mean is: in an big project, there will be multiple levels of Elevations.. if i want to be sure that my dialog is on the top of everything, i have to put elevation 10000000 (example)?
there is no a more elegant way to do it?

this is the layout of my dialog
Cattura.PNG


Brown panel is child of violet.

violet has elevation of 10 (value never used, the highest in the all app)

same result, it is not on the top
 
Upvote 0

Cableguy

Expert
Licensed User
Can you provide a sample app that demonstrates this behaviour?

I am guessing that the issue here is that they have different parents... and althought your dialog has the highest elevation to its parent, its parent is not the most elevated one in your layout...
 
Upvote 0

Filippo

Expert
Licensed User
Thanks for linking!
Actually i know what is elevation, i use multiple levels of elevation in my app. in some case just to get a good shadow.

what i mean is: in an big project, there will be multiple levels of Elevations.. if i want to be sure that my dialog is on the top of everything, i have to put elevation 10000000 (example)?
there is no a more elegant way to do it?

this is the layout of my dialog
View attachment 104953

Brown panel is child of violet.

violet has elevation of 10 (value never used, the highest in the all app)

same result, it is not on the top
Always put the violet panel at the end of the tree, then you no longer have to set the elevation to 100000.
1609010605474.png
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
@Cableguy @Filippo
Here you are the Example

How to test:
  1. Tap on "Button"
  2. Two panels will appear, "qrcodeReader" (elevation 5) and on top of it "pnlScanner" (elevation 6). In "pnlScanner" there are some buttons, label and imageview.
  3. Tap on the button with the "keyboard" icon
  4. The dialog will appear, but it is UNDER the "qrcodeScanner" panel. as you can notice.
    The "pnlTapOutDialog" has elevation of 10 in the designer
  5. Tap on "Cancel" to return in beginning conditions, OR tap on the dialog buttons
 

Attachments

  • TestDialogs.zip
    18.6 KB · Views: 76
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
As I stated, its a Parent problem...

Change your call to this:

B4X:
    ....
    Wait For (showInputDialog(pnlScanner, "Title", "", "", "Ok", "Cancel", False)) Complete (Result As Map)
    If Result.Get("Input") <> "" Then....
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
As I stated, its a Parent problem...

Change your call to this:

B4X:
    ....
    Wait For (showInputDialog(pnlScanner, "Title", "", "", "Ok", "Cancel", False)) Complete (Result As Map)
    If Result.Get("Input") <> "" Then....

Well actually "qrcodeReader" and "pnlScanner" are both child of "Activity", and "pnlTapOutDialog" its added too
with elevation of 5, 6, 10000 in order... why i've to specify "pnlScanner" as parent?...

it is far from the concept of modal dialog...
example, if in the future i will add another panel with greater elevation, i've to update also the code for the dialog... this sound very particular.. well..

i think i solved my problems thanks to Informatix library, exactly what i was looking for: NATIVE dialogs

I will take a very thorough look to b4xdialogs in the future if i will need more customized dialogs... though i think they have to be MORE modal/popup/dialog
 
Upvote 0

Cableguy

Expert
Licensed User
For a dialog as simple as that, i would have created it myself with all the needed features returning the map... also, i dont think you need to call it using resumable subs... a " normal call would sufice, both in the show dialog call as inside the show dialog map creation.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
i dont think you need to call it using resumable subs... a " normal call would sufice
I used resumable in order to use the "WaitFor", B4Xdialogs are not locking...
i need to stop the code until the user answer, because can happen that multiple dialogs are fired, so.. one per time



i would have created it myself
i tried, i got problems with "IME", that fires two times consecutively on my phone when i set the keyboard on "NUMBERS" (and i know why, it does not depends on me) and then never again (this i don't know why)...
so.. waste of time solving problems to do such a simple thing, when Andoird provides the method to do it, but it is not implemented in B4A...
or better, informatix did it more or less.. thanksfully
 
Upvote 0
Top