Android Question Click event "inside a loop cicle"

LucaMs

Expert
Licensed User
Longtime User
An Italian member asked how to catch a click event (of an ImageView) from within a Do While loop.

He also wants the cycle starts when the app starts.

I posted an example (which I attach here); on my phone it works, not on his device.

When he "tap"s on the image, does not happen anything.

Little help? Thank you
 

Attachments

  • lm Click into Loop2.zip
    94 KB · Views: 170

klaus

Expert
Licensed User
Longtime User
An Italian member asked how to catch a click event (of an ImageView) from within a Do While loop.
He or you need to explain what exactly the program is supposed to do.
Why trying to check if an ImageView has been clicked, why not using the events directly ?
To me it looks that the user is not used to event driven operating systems.
It reminds me the (very) old Basics where we had an 'infite' loop waiting for and detecting user intervetions, but this has been improved with the event driven systems.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I do not know the precise purpose.

His explanation is roughly:

"I would like to display two images which continue to alternate and when the user clicks on one of them, alternating stops" (and then the "real game" starts).

Have you tried the attached project, Klaus? Works it?

Thanks for your reply
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have looked at the code but haven't tried it.
Before answering a question I want and need to know the problem.
And here I don't know nor undestand what the real problem is and what exactly the user wants or expects.

I have tried to explain what he wants to achieve. I can add a link he posted.


Also remember you cannot catch mist events in a do while loop.
Don't use it.

"mist" events? I do not know what it means.
I know only that code works on my device and not on his own, so I thought to ask others to test it.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try the attached code.
The problems in your code are:
- The images switch too fast. From what I have seen in the italian forum he wants 2 seconds between image switches.
- Your code is an infinte loop, when you go back from the actQuiz Activity to Main Activity this one launches actQuiz again.

A Timer is the solution not a loop !

I saw in your code:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    ' Attention: UserClosed will be True even if orientation changes.
This is wrong !
UserClosed = False when the orientation is changed !
 

Attachments

  • lm Click into Loop3.zip
    93.4 KB · Views: 191
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Try the attached code.
The problems in your code are:
- The images switch too fast. From what I have seen in the italian forum he wants 2 seconds between image switches.
Yes, I now, but it was only an example on how to catch the event
- Your code is an infinte loop, when you go back from the actQuiz Activity to Main Activity this one launches actQuiz again.
This is due to the fact that he wanted to start the animation automatically and I put the call in the Main Resume
A Timer is the solution not a loop !

I saw in your code:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    ' Attention: UserClosed will be True even if orientation changes.
This is wrong !
UserClosed = False when the orientation is changed !
Yes, thank you, it is part of the template B4A, i forgot to remove it

Thanks, Klaus, I point out to him your post.
 
Upvote 0
Top