How to change button image when clicked??

Darkeye

Member
I have a play button and i set the image on that button at design time by changing drawable to statelist drawable and then adding the image path in image

but i want to write a code that changes the image to pause image when clicked

so how to change it.

i tried this, but dont know what to write in between parenthesis
Button1.SetBackgroundImage

any help ?? :BangHead::BangHead:
 

mangojack

Expert
Licensed User
Longtime User
Darkeye .. welcome to the forum .. this should help

B4X:
Sub Globals      
   Dim Button1 As Button
   Dim ImagePause As Bitmap   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   ImagePause = LoadBitmap(File.DirAssets,"pause.jpg")
End Sub

Sub Button1_Click   
   Button1.SetBackgroundImage(ImagePause)
End Sub

this is on the assumption you have added a "paused image file" to the file assets list ..

Cheers mj
 
Last edited:
Upvote 0

Darkeye

Member
Got 1 more problem here,

i did everything as u said, i gave the path to the image file, and all there images are present in files folder, in designer button is in statelist drawable but when i ran the application in emulator, all the images are gone, there are about 8 images and i cant see any of them.. any help..

do i have to all images somewhere in memory of android emulator.

please help.. :sign0104:
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Can you upload you project ? File > Export as zip

Cheers mj
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Darkeye .. you must load your layout first, have a look at the attached zip. As you assigned all the images to the button pressed states within the designer , there was no need to load bitmaps from the activity.

If you have not already done so this might be worth a read, especially about page 160 that has some great code examples
Beginners Guide

Cheers mj
 

Attachments

  • Player Layout 2.zip
    97.4 KB · Views: 256
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Klaus .. confused? Although not a direct link it was a link to download the current edition of beginners guide .. no?

Cheers mj
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Klaus .. confused?
No.

I was wondering about the reference to page 160 wich is chapter 10 Variables and Objects.
If you have not already done so this might be worth a read, especially about page 160 that has some great code examples
Best regards.
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Klaus .. this is just for reference but , I have just downloaded another "copy".
I have had on my desktop since Sept , version 6.1.7601 - 253 pages 50mb. I have just downloaded version 6.1.7601 - 283 pages 53.1mb .. ?? .

Regardless it was a wakeup call to the Users guide as a lot of my searches within the forum are covered nicely within the guide .. SQL ect.

Thanks again and Darkeye sorry for straying off topic.

Cheers mj
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Also off topic.
Where do you get these version numbers 6.1.7601 from ?
On all Guides you find at the bottom of the cover page the date of the last update and an Edition number.
You also find the current Edition numbers on top of the Documentation webpage for both Guides, v2.4 for the Brginner's Guide and v1.2 for the User's Guide.

Best regards.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Klaus , the version number is the same for all downloaded B4a PDF's.. the version of novaPDF they were created with !
I now have the current version of the beginners guide which I'm rolling up now for a few whacks of the head.

Cheers mj
 
Upvote 0

Darkeye

Member
Darkeye .. you must load your layout first, have a look at the attached zip. As you assigned all the images to the button pressed states within the designer , there was no need to load bitmaps from the activity.

If you have not already done so this might be worth a read, especially about page 160 that has some great code examples

Cheers mj

Ok got it thanks,,... :D
 
Last edited:
Upvote 0
Top