Android Question How to programm modal input window?

welu1805

Active Member
Licensed User
Longtime User
Hi all,

on my main activity I want to press a button, than should come a window with input fields (edittext). This window should be modal. How can I programm this on principle?

Thanks
Lutz
 
What help do you need exactly? Making the popup modal? Place a panel behind it with a click sub and return true
 
Upvote 0
Thank you JonPM,

that was my problem. How to catch the click event of the panel. Now it works. Return True is not nessecary because pnlScreen_Click has no ReturnValue.

One small problem is still: If I press the Back-key I expect that only the modal dialog will be closed but the app closes.
 
Upvote 0
You need to manage this in the Activity_KeyPress event, something like this:
Code: Copy
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK
        If PanelX.Visible = True Then
            PanelX.Visible = False
            Return True
        Else
            Return False
        End If
    End If
End Sub
 
Upvote 0
I want to create an own class for the dialog. Is it possible to trap the Activity_KeyPress event within this class?
 
Upvote 0
Hi all, best wishes for the new your!

Now I tested the library "DialogView". If I call a simple modal dialog with the folloing code

Dialog.LoadLayout("dialog1").ShowYesNo("Login", "yes", "no")

a modal dialog window appears. After pressing the back key THIS DIAOLG is closed and not the app. Because it runs in debug mode I can see that there is no new activity. Therefore it MUST be possible to trap the back key in the Dialog class in the library.

How does it work?
 
Upvote 0
I found a solution which also works within a class:

In the class is a panel for the background of the dialog called "pnlBackground"
Further there is a Sub "Show" which sets pnlBackground.Visible = True.

I added this code after "pnlBackground.Visible = True":

Dim r As Reflector
r.Target = pnlBackground
r.SetOnKeyListener("OnKeyPress")
r.RunMethod2("setFocusable", "True", "java.lang.boolean")
r.RunMethod2("setFocusableInTouchMode", "True", "java.lang.boolean")
pnlBackground.RequestFocus

This is the Sub "OnKeyPress":

Sub OnKeyPress(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
If pnlBackground.Visible Then
pnlBackground.Visible = False
Return(True)
Else
Return(False)
End If
Else
Return(False)
End If
End Sub

Now the back key closes only the dialog.
 
Upvote 0
You should use the
Code: Copy
 Tags when you post code.
[ATTACH=full]40231[/ATTACH]
 

Attachments

  • upload_2016-1-3_15-43-40.png
    upload_2016-1-3_15-43-40.png
    18.8 KB · Views: 252
Upvote 0
This is #14 again with formatted code:

I found a solution which also works within a class:

In the class is a panel for the background of the dialog called "pnlBackground"
Further there is a Sub "Show" which sets pnlBackground.Visible = True.

I added this code after "pnlBackground.Visible = True":

Code: Copy
Dim r As Reflector
r.Target = pnlBackground
r.SetOnKeyListener("OnKeyPress")
r.RunMethod2("setFocusable", "True", "java.lang.boolean")
r.RunMethod2("setFocusableInTouchMode", "True", "java.lang.boolean")
pnlBackground.RequestFocus

This is the Sub "OnKeyPress":

Code: Copy
Sub OnKeyPress(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
  If KeyCode = KeyCodes.KEYCODE_BACK Then
    If pnlBackground.Visible Then
      pnlBackground.Visible = False
      Return(True)
    Else
      Return(False)
    End If
  Else
    Return(False)
  End If
End Sub

Now the back key closes only the dialog.
 
Upvote 0
Back
Top