Android Question How to get the android button from anywheresoftware.b4a.objects.ButtonWrapper

EduardoElias

Well-Known Member
Licensed User
Longtime User
I am trying to solve this problem:

Tha b4A code is as follows:

B4X:
Sub SetupPinpad(bt1 As Button, bt2 As Button, bt3 As Button, bt4 As Button, bt5 As Button, bt6 As Button, bt7 As Button, bt8 As Button, bt9 As Button, bt0 As Button, btCancel As Button, btConfirm As Button, btClear As Button, act As Activity)
    LogColor("yNexu.SetupPinpad", Colors.Green)
    nexupayment.RunMethod("SetupPinpad", Array(bt1.Parent, bt2.Parent, bt3.Parent, bt4.Parent, bt5.Parent, bt6.Parent, bt7.Parent, bt8.Parent, bt9.Parent, bt0.Parent, btCancel.Parent, btConfirm.Parent, btClear.Parent))
End Sub

the #JAVA code is

B4X:
    public void SetupPinpad(Button bt1, Button bt2, Button bt3, Button bt4, Button bt5, Button bt6, Button bt7, Button bt8, Button bt9, Button bt0, Button btCancel, Button btConfirm, Button btClear) {
        BA.Log("Transaction.SetupPinpad");
        destaxaSDK.setPinPadKeyboard(bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, bt0, btCancel, btConfirm, btClear, ba.activity);
    }

I create this buttons manually using clsFLoatingWindows in a panel to simulate a virtual numeric pinpad

I have the B4A button and I am aware that it is a wrapper.... However I need to pass the Java Button to be used

Tried to use button directly when using RunMethod but it does not match the calling signature in JAVA, so I changed to .parent but it is causing the library (3rd party) to crash

How can I do that?
 
Last edited:

drgottjr

Expert
Licensed User
Longtime User
did you try using javaobject? i just assign a button to a javaobject and run some methods (eg, getTag() and setBackgroundColor()). both work as expected (when i tap the green button, it turns red).

B4X:
dim jobutton1,jobutton2,jobutton3, ... as javaobject
dim bt1,bt2,bt3, ... as button

btn1.initialize() ...

jobutton1 = bt1
jobutton2 = bt2
jobutton3 = bt3

nexupayment.RunMethod("SetupPinpad", Array(jobutton1,jobutton2,jobutton3,...)

see attached.
 

Attachments

  • 1.png
    1.png
    26.9 KB · Views: 149
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
did you try using javaobject? i just assign a button to a javaobject and run some methods (eg, getTag() and setBackgroundColor()). both work as expected (when i tap the green button, it turns red).

B4X:
dim jobutton1,jobutton2,jobutton3, ... as javaobject
dim bt1,bt2,bt3, ... as button

btn1.initialize() ...

jobutton1 = bt1
jobutton2 = bt2
jobutton3 = bt3

nexupayment.RunMethod("SetupPinpad", Array(jobutton1,jobutton2,jobutton3,...)

see attached.
I have tried this and did not work, I am trying to get the widget button that I beleive is what the B4A button is wrapping
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
_bt1 is the wrapper, _bt1.getObject() is the Button (android.widget.Button)

what do you mean by "I have tried this and did not work" ? what did you try? my example? (my example works). if you tried something else, what was it? show the error log.

unfortunately, buttons have no methods of their own to show in a test; they inherit view methods. in my example, if i pass a b4a button as a javaobject, i can run 2 inherited methods. the javaobject is a button.

look at the attached.
if i pass a b4a button (buttonwrapper, according to you) to test what it is, it's an android.widget.Button.
if i take a javaobject and assign it to a b4a button and pass it to the test, it's an android.widget.Button.
if i instantiate an android.widget.Button and pass it to the test, it's an android.widget.Button.
if i take a webview and test it, it's not an android.widget.Button (that's a test of the test).
except for the webview, the others are all instances of android.widget.Button.

Like Reply
 

Attachments

  • 1.png
    1.png
    47.4 KB · Views: 129
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
_bt1 is the wrapper, _bt1.getObject() is the Button (android.widget.Button)

what do you mean by "I have tried this and did not work" ? what did you try? my example? (my example works). if you tried something else, what was it? show the error log.

unfortunately, buttons have no methods of their own to show in a test; they inherit view methods. in my example, if i pass a b4a button as a javaobject, i can run 2 inherited methods. the javaobject is a button.

look at the attached.
if i pass a b4a button (buttonwrapper, according to you) to test what it is, it's an android.widget.Button.
if i take a javaobject and assign it to a b4a button and pass it to the test, it's an android.widget.Button.
if i instantiate an android.widget.Button and pass it to the test, it's an android.widget.Button.
if i take a webview and test it, it's not an android.widget.Button (that's a test of the test).
except for the webview, the others are all instances of android.widget.Button.

Like Reply
RunMethod already converts it to Object

However in the inline Java code I need to call a SDK that expect android.widget.Button as a parameter

So, the B4a Button is a wrapper: anywheresoftware.b4a.objects.ButtonWrapper that I found somewhere is a wrapper of the android button

I would like to know how to get the android button from the B4A button...... I have no idea how this is organized or done in b4a/java, maybe I am asking something stupid, but looking for help
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
The code fragment and his commentary that @drgottjr posted above shows that passing a B4A wrapped Button unwraps it when passing it to RunMethod so the method receives an android Button. So the following should work for you.

B4X:
Sub SetupPinpad(bt1 As Button, bt2 As Button, bt3 As Button, bt4 As Button, bt5 As Button, bt6 As Button, bt7 As Button, bt8 As Button, bt9 As Button, bt0 As Button, btCancel As Button, btConfirm As Button, btClear As Button, act As Activity)
    LogColor("yNexu.SetupPinpad", Colors.Green)
    nexupayment.RunMethod("SetupPinpad", Array(bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, bt0, btCancel, btConfirm, btClear))
End Sub
 
Upvote 0
Top