Touch events

anaylor01

Well-Known Member
Licensed User
Longtime User
I am working on a panel that is going to have lines on it. I want to do something when the user click on a line. How would I set this up? Do I define the dimensions of each line? Do I use a case statement to determine each line? Each resolution is different so how could I program for that?
 

anaylor01

Well-Known Member
Licensed User
Longtime User
Since the clickable area is going to be a rectangle and that area is going to change by device because of screen size/resolution and orientation what is the best way to program for that? I can't hard code specific areas.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Could you be more precise on what exactly you want to do.
How are the lines drawn?
If you have drawn them you know their coordinates.
In the Touch event you get the cursor (finger) coordinates so you can check if the cursor coordinates lie on the line or above or below.

Best regards.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
How can I put this. The rectangle is going to be panel width. Lets say 30 pixels in height. That gives me a rectangle of space that the user can click. That rectangle's size is going to change on different devices. How can I program the area to catch if the rectangle is always changing size? I plan on programming these lines(rectangles) to be a certain percentage of screen size so they will not all be the same size. How do I get the clickable area for that? The X and Y for the touch is always going to be different depending on the device.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
Now I am trying to put an image at the front of each line. But I am having troubles making the panel the parent and also getting it to line up correctly. Can you take a look at the code and push me in the right direction? Thanks.
B4X:
   Sub Activity_Resume
   Dim i As Int
   Dim y As Float
   Dim lines As Int
   lines = pnltest.Height / 40
   For i = 1 To lines
      y = i * 0.08 * pnlTest.Height
   iv(i).Initialize("pnltest")
   Activity.AddView(iv(i), 0, y,20, 50) ' ltwh
   iv(i).Bitmap = LoadBitmap(File.DirAssets, "checkbox_checked.png")
      cvsTest.DrawLine(0, y, pnlTest.Width, y, Colors.Red, 3) 
   Next
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I would suggest you to draw the bitmaps directly onto the panel with cvsTest.DrawBitmap(....
It would be easier to give you the best answer if you posted your project as zip file. So we could see what you have already done and could directly modify it.

Best regards.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
Basically it is going to be a checkbox. And when the user click it it will change image from checked to unchecked and vice versa. Will I be able to do that with bitmap like that?
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
I think I understand. You declare a Rectangle location and size to draw the bitmap to. What I am trying to do is put a checkbox at the beginning of each red line. It's not doing what I want. here is my code.
B4X:
Sub Activity_Resume
   Dim i As Int
   Dim y As Float
   Dim lines As Int
   lines = pnltest.Height / 40
   Dim x As Int
x = 10
   For i = 1 To lines
      y = i * 0.08 * pnlTest.Height
   iv(i).Initialize("pnltest")
   Activity.AddView(iv(i), 0, y,20, 50) ' ltwh
   Dim Bitmap1 As Bitmap
Bitmap1.Initialize(File.DirAssets, "checkbox_checked.png")
Dim DestRect As Rect
DestRect.Initialize(0dip, x, 35dip, 300dip)'l,t,w, h
cvstest.DrawBitmap(Bitmap1, Null, DestRect) 
   'iv(i).Bitmap = LoadBitmap(File.DirAssets, "checkbox_checked.png")
      cvsTest.DrawLine(0, y, pnlTest.Width, y, Colors.Red, 3) 
      x = x + 10
   Next
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Why don't you use standard CheckBoxes ?

Could you post your test program as a zip file.
It would be much easier to help you !

It would also have been easier if you had explained completely what you want to do from the beginning. Instead of the step by step evolution.

Best regards.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
I'm sorry Klaus. I guess I didn't explain myself very well. Don't you read minds? LOL. I think your right. I should use regular check boxes and set the background as my image. You should know by now I am not the sharpest knife in the drawer. I attached my project.
 

Attachments

  • Notes.zip
    33.3 KB · Views: 217
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
Got another issue. I am adding an edittext box and a button below the panel. I keep getting a nullvalueexecption when I try to set the top of the edittext box to the height of the panel. The procedure is "Sub btnlist_click". I have attached the zip.
 

Attachments

  • Notes.zip
    32.6 KB · Views: 194
Upvote 0

klaus

Expert
Licensed User
Longtime User
As Erel already wrote, you try to set layout parameters before having added the view somewhere.

In the btnList_Click routine you initialize the new views but you don't add them to the Activity.
You shoudn't set the new views in the btnList_Click routine, but in Activity_Create routine where pnlTest is created and added, because you would add these views every time you click the btnList button.

I would suggest to put all views displayed with the btnList button in one panel, so you just need to set this panels Visible parameter to False or True.
I would do the same for the main layout, put all viees on a panel.

Attached you find your program modified.

Best regards.
 

Attachments

  • Notes2.zip
    32.6 KB · Views: 232
Upvote 0
Top