CustomDialog and Events

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I am trying to use the CustomDialog to create a modal dialog box. I am using Classes in B4A 2.0 – really neat.

I have a Panel (p1) that contains a ScrollView. The ScrollView is populated with 20 or so labels (that scroll vertically). If a person clicks on a label I want it to trigger a click event.

If I add p1 to the Activity, my click events trigger when a label is tapped.

With identical code only adding p1 instead to a CustomDialog, visually it shows properly and the modal-ness works, but tapping on a label does not fire the click events.

When using the CustomDialog I can scroll the labels vertically within the ScrollView so I know there's not an invisible panel capturing touch events.

Any idea why label click events do not fire when using the CustomDialog?

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Can you upload your project?

Hello,
Thanks for looking at this

This test app shows a File Dialog.

It is currently configured in what I call "CustomDialog" mode. To change it to "Activity" mode several lines of code need to be commented. I did it this way to show that it is essentially using the same code.

To have the program run in "Activity" mode, in the FileDlg module (which is a class – thanks) comment the three lines of code near lines 278, 279, and 280 in the Show sub.

It's also handy to put a breakpoint at line 290 (in the FDpn_Click sub) in the FileDlg module to see if the "file label" event fires in response to a click on a file or directory name within the ScrollView.

For me, this event fires when in "Activity" mode but does not fire when I am in "CustomDialog" mode. The ScrollView does scroll in both modes.

Barry.
 

Attachments

  • FileDlg.zip
    2.6 KB · Views: 432
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
You only uploaded the class module. I think that it is not possible to handle events while a modal dialog is displayed (not 100% sure).

In the DialogsDemo Custom and Custom2 show a button in a CustomDialog handling a Click event while the dialog is displayed.

Sorry. I don't know I got a zip file with only one file. But I have uploaded a new zip with the entire test project directory. (I used the export function and triple checked this time).

Agraham, yes I have looked at the demo and most of the prior posts asking similar questions. The demo does work on my devices. I pretty much copied the code I use directly from the demo. The fact that it works there and not here is confusing.

Thanks,
Barry.
 

Attachments

  • FileDlg3.zip
    30.2 KB · Views: 375
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
I don't understand your code but if I put something like

ToastMessageShow("btFDOk_Click", True)

in each of your click events then I can see that they are being called OK.


Thanks. I've added ToastMessages to all my Click event subroutines. I've also added a screenshot from my Samsung Vibrant to the zip file.

On both my Samsung Vibrant (Android V2.2) and my Acer A500 (Android V4.03) none of my click events fire; no ToastMessages show. The significant click events are for 1. the up arrow at the top, 2. clicking on any of the lines in the ScrollView to select a file or move to a directory, and 3. my two buttons "Ok" and "Cancel". The two buttons from the Custom Dialog, "Ok" and "Cancel", at the bottom both work on my devices. If I get the CustomDialog to work I will remove my Ok and Cancel buttons since they will be redundant.

If in your testing the ToastMessages display upon clicking, that will be interesting.

If I comment out the three lines 278, 279, and 280, then re-compile and re-run, this removes the CustomDialog. Now all my events fire properly on my devices and the ToastMessages show, but I lose Modal-ness, which I really like.

Thanks,
Barry.
 

Attachments

  • FileDlg4.zip
    116.7 KB · Views: 349
Upvote 0

agraham

Expert
Licensed User
Longtime User
Sorry :sign0161: I missed that in FileDlg3 you had commented out those three lines and it was in "Activity mode". I also don't get the events fired when in "Modal mode". I don't know why as the events from a modal dialog in the CustomDialogs demo works fine with Basic4android 2.0 so I can only surmise the failure is something to do with them being located in a Class.
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
I can only surmise the failure is something to do with them being located in a Class.

I will check it.

Thanks. I modified my test application to not use classes. The same problem happens in "CustomDialog" mode. The events for my buttons or tapping within the ScrollView do not fire. I then commented out the three lines changing the test application to "Activity" mode – no CustomDialog. My button click and Scroll View taps now fire.

I have attached both versions, "CustomDialog" and "Activity", of the test application that does not use classes. Do you get the same results?

Barry.
 

Attachments

  • FileDlg5 Activiy.zip
    29.9 KB · Views: 383
  • FileDlg6 Cust Dlg.zip
    29.9 KB · Views: 448
  • Screen Shot Samsung Vibrant.png
    Screen Shot Samsung Vibrant.png
    88.4 KB · Views: 637
Upvote 0

agraham

Expert
Licensed User
Longtime User
Do you get the same results?
Yes. Custom Dialog itself does nothing to aid (or otherwise) the propagation of events. It seems odd to me that some work and some apparently don't but I don't fully understand the Basic4android modal code and its relationship to Android messaging to explain it. I guess only Erel would have the necessary insight if he can be bothered to shine his intellect upon it!
 
Last edited:
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Note that another option is to use CallSubDelayed:

...

This can be useful if you do not want to call it in Activity_Resume for some reason.

Thank you. This is good information to have. I implemented opening the file dialog in response to a button click instead of within the Activity Create module. My events now fire as expected from within the Custom Dialog.

Barry.
 
Upvote 0

dexMilano

Active Member
Licensed User
Longtime User
Hello all,
I'm restarting this topic because I think I have a similar problem.
I've a button that opens a custom dialog with a scroll view that should be updated every tap on inself.
It seems that taps are not executed when the dialog is opened.
When I close it the events are fired.
But this is not useful because the content of the listview should be updated in the dialog.

Thanks

dex
 
Upvote 0
Top