Android Question Oneshot delay to display an image

ardhuru

Member
Licensed User
Longtime User
Hello,

Please excuse my asking about what I suspect has a very simple solution.

I have 2 images; Imageview1 shows up as LED_Off.png by default. During operation, if a certain thing happens, Imageview should change over to Red_LED_ON.png, stay for 2 seconds, and then revert back to LED_off.png.

How exactly would I go about this? Whatever rudimentary (and idotic, I'm sure) things I tried, dont seem to wrk.

In effect, this is what I want:

If code has reached this point:

ImageView1.Bitmap=LoadBitmap(File.DirAssets,"Red_LED_ON.png")
Pause 2 seconds
ImageView1.Bitmap=LoadBitmap(File.DirAssets,"LED_Off.png")

So, how do I achieve the 2 seconds delay? I tried to make sense of timer, callsubdelayed, callsubplus and am nowhere closer to sorting it out.
 

DonManfred

Expert
Licensed User
Longtime User
How exactly would I go about this?
CallSubPlus is great for you
See https://www.b4x.com/android/forum/threads/callsubplus-callsub-with-explicit-delay.60877/#content

I tried to make sense of timer, callsubdelayed, callsubplus and am nowhere closer to sorting it out.

See attached example

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim greenled, redled As Bitmap
    Private ImageView1 As ImageView
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    greenled.Initialize(File.DirAssets,"green-control-md.png")
    redled.Initialize(File.DirAssets,"led-red-control-md.png")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
    ImageView1.Bitmap = greenled
    Starter.csu.CallSubPlus(Me, "Sub_1", 2000)
End Sub

Sub sub_1
    ImageView1.Bitmap = redled   
End Sub
 

Attachments

  • ledtest.zip
    58.1 KB · Views: 132
Upvote 0

ardhuru

Member
Licensed User
Longtime User
Wow, that was fast!

Manfred, thank you very much, this is exactly what I needed.

Despite the link, I couldnt have proceeded without your ready example. Thanks again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…