B4J Question How to get view,node ?

hookshy

Well-Known Member
Licensed User
Longtime User
I have 4 buttons that will have to mouve 20 images on the screen
instead of coding
B4X:
Sub btn_left_MouseClicked (EventData As MouseEvent)

img_1.left=img_1.left-1dip
img_2.left=img_2.left-1dip
.
.
.
img_100.left=img_100.left-1dip
End Sub
I need a function to get the view and use single statement
img_x.left=img_x.left-1dip in all 4 buttons coresponding for move to left,right,top,bottom


I am new with b4j ..so do not laugh ..the sub below is crashing my brain
B4X:
Sub get_view As ImageView

Dim xv As ImageView

Select mystring 

Case "img_test"
xv=img_test  
Case "img_pa1"
xv=img_pa1
  
End Select  

Return xv
End Sub
 

Daestrum

Expert
Licensed User
Longtime User
Put the imageviews in an array
B4X:
Dim img(20) as Imageview
Then you can use a for-next loop to cycle through them
B4X:
for a = 0 to 19
    img(a).left = img(a).left -1
next
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
sory I did not asked right ...my img are not quoted as an array ...
the names would be ...img_pa1, img_pa2, img_gr1, img_s3,img_m2 ...

I select a view with mouse clicked ...and with the 4 buttons I mouve the selected view to left,right, top and bottom ...
the sub btn_left_mouseclicked ... must receive a view coresponding to the selcted view
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Ok ...I have solved the problem by initialising all views with
imgx.initialise("img")
imgx.tag="imgx"
anyway my example does not fit for a general case so I had to change a bit the code
Thank you!

B4X:
Sub btn_left_MouseClicked (EventData As MouseEvent)

Dim img_x As ImageView
img_x=pnl_tixi.GetNode(get_nodindex)
img_x.left=img_x.left-1dip

End Sub  
Sub btn_right_MouseClicked (EventData As MouseEvent)
Dim img_x As ImageView
img_x=pnl_tixi.GetNode(get_nodindex)
img_x.left=img_x.left+1dip

End Sub  
Sub btn_up_MouseClicked (EventData As MouseEvent)
Dim img_x As ImageView
img_x=pnl_tixi.GetNode(get_nodindex)
img_x.top=img_x.top-1dip

End Sub  
Sub btn_down_MouseClicked (EventData As MouseEvent)
Dim img_x As ImageView
img_x=pnl_tixi.GetNode(get_nodindex)
img_x.top=img_x.top+1dip

End Sub  
Sub get_nodindex As Int

Dim xv As Int

Select imgtag

Case "img_pa1"
xv=img_pa1.Id

Case "img_gr1"
xv=img_gr1.Id

End Select  


Log("view"&xv)
Return xv
End Sub
 
Upvote 0
Top