RotatingNeedle Example - Help Needed

MCU01

Member
Licensed User
Longtime User
Hi all,

I'm new to Basic4Android and I have been playing with the examples in the beginner's guide. I have been modifying and playing with the RotatingNeedle example and I have a question. I want the user to be able to tap on the compass and make something happen. For example, I want this code to work

B4X:
Sub imvCompass_Click

   .... do something

End If
But it just doesn't work :BangHead:. Since the ImageView is associated with a rectangle and a canvas the above code just doesn't work.

Thank you all for your help,

Robert
 

MCU01

Member
Licensed User
Longtime User
Can you upload your project (File - Export as zip) ?

It's the same project as in the guide. Just add the lines

B4X:
Sub imvCompass_Click   
   btnMode.text = "texting"   'Any code to test the sub
End If

Should it work or not? Thank you.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should change line 24 :
B4X:
imvCompass.Initialize("")
to
B4X:
imvCompass.Initialize("imvCompass")
It's necessary to declare an EventName to get the event routine working.
As no event was required in the original code, so no EventName was given.

Best regards.
 
Upvote 0

MCU01

Member
Licensed User
Longtime User
You should change line 24 :
B4X:
imvCompass.Initialize("")
to
B4X:
imvCompass.Initialize("imvCompass")
It's necessary to declare an EventName to get the event routine working.
As no event was required in the original code, so no EventName was given.

Best regards.

Thank you Klaus. That fixed it.

Robert
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
Graphics not fully displayed

I have just been playing with the rotating needle example and thought i would use different graphic file (attached). i changed to code to load the files below:

B4X:
bmpCompass.Initialize(File.DirAssets,"compass1.png")
bmpNeedle.Initialize(File.DirAssets,"compassneedle.png")

The problem i am getting is that the compass1.png seems to be too big for the box and you only see the center part of the graphic, not the circle with the graticules.

the rest of the code has not changed, can anyone see why it doesn't work correctly

thanks
 

Attachments

  • compass1.png
    compass1.png
    22.1 KB · Views: 319
  • compassneedle.png
    compassneedle.png
    292 bytes · Views: 351
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should move this line
B4X:
imvCompass.Bitmap = bmpCompass
after this line
B4X:
RectCompass.Initialize(0, 0, bmpCompass.Width, bmpCompass.Height)
imvCompass.Bitmap = bmpCompass
This happend when the densitiy is grater than 1.

Best regards.
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
Thanks, that was it was :)
 
Upvote 0

MaAncheNo

Member
Licensed User
Longtime User
Just another pair of images for the compass.

Thank you all for your help.
 

Attachments

  • Compass.png
    Compass.png
    137.9 KB · Views: 341
  • Needle.png
    Needle.png
    5.7 KB · Views: 333
Upvote 0
Top