B4J Question Drag the buttons - Invert buttons

WebQuest

Active Member
Licensed User
Hello Community,
I'm having trouble developing a function for my program. The problem is, I can't find a solution to swap any button dragged to another button. I am using the MouseDragged and MousePressed event to drag buttons to other locations, but I also wish that when a button is dragged to another button the dus swap positions. Anyone have any solutions? Any example will be appreciated.

1639881685261.png
 

WebQuest

Active Member
Licensed User
Thanks ilan I made the changes, but as explained in post # 19 the release keys don't resize well. What am I doing wrong? I have attached the project.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Here you are.
You need to create a B4XPage_Resize routine and move buttonOrgSize = ... there.
And to get it work correctly I had to change the parent of the last 8 buttons from Main to Panel1 because the positions were not OK.
Without having the project it would have been almost impossible to find the problems.
 

Attachments

  • Project1.zip
    18.2 KB · Views: 109
Upvote 0

ilan

Expert
Licensed User
Longtime User
Here you are.
You need to create a B4XPage_Resize routine and move buttonOrgSize = ... there.
And to get it work correctly I had to change the parent of the last 8 buttons from Main to Panel1 because the positions were not OK.
Without having the project it would have been almost impossible to find the problems.
I did exactly the same in my project post #18.

Really sad that @WebQuest did not have alook at it.
 
Upvote 0

WebQuest

Active Member
Licensed User
Sorry guys I looked at everything. Now it seems to work thanks. One last thing, do the buttons need to be set to Enabled = false? Next I need the click event.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Now it seems to work thanks.
What does this mean ?
The code I posted works!
I tested it before posting.

One last thing, do the buttons need to be set to Enabled = false? Next I need the click event.
Sorry, but you need to give more precise information on what exactly you want to do.
Why Enabled = False ?
You can define a same EventName for all Buttons and have one Click event and use the Tag property to know which Button raised the event.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Why Enabled = False ?
the problem is that changing it to true will not allow the touch event of the Pane to be triggered. not like in b4a in b4j the button behaves differently.
this is why i changed them to enable= false

in my opinion, i would not use buttons. i would use labels instead and then they can be enabled=true.

You can define a same EventName for all Buttons and have one Click event and use the Tag property to know which Button raised the event.

this will not work. you cannot handle the pane_touch event and also the button_click event.
i really don't understand what the end result should look like but to be honest i think that after giving several projects code and really solving the most problems it is time for @WebQuest to try by himself. At the end he is the one that should create his own app 😁
 
Upvote 0

WebQuest

Active Member
Licensed User
Hi Iliano,
Your code only works with buttons disabled. Is there a way to run your code with buttons enabled?
 
Upvote 0
Top