Android Question How can read all same controls from activity, panel, B4xPages from parent ?

dws

Member
Licensed User
Longtime User
I have created a control (Class Module - Custom View (XUI) with Name MyComboBox ).
Its placement in Activity or Panel or B4XPages is done normally with both the designer and the code.

How can I (within the control) read all the same controls I have placed in the same Activity or Panel or B4XPages.

I try to put this code inside to my control in Sub Show to close all popups from the same controls before open to focused control.

B4X:
For Each v AS B4XView In CallBack
    If v Is MyComboBox Then
        Dim mc As MyComboBox = v
        v.Hide
    End If
Next

Where CallBack is then container than put then controls ( Panel, Activity, B4XPage )

Any Help
 

dws

Member
Licensed User
Longtime User
Thanks EREL.

I tried the example of the code you give me before posting my first question. Unfortunately I get error that it does not recognize view.View ...

I will ask my question in a different way.
It is possible through the code of a control to read the data located in the same activity or panel.

Example.
The control is a Combobox. When selected for pop-up development, we want to check if there are other ComboBoxes mounted on the same panel or Activity to automatically close any pop-ups of other comboboxes.
 
Upvote 0

dws

Member
Licensed User
Longtime User
Thanks Erel.

Yes i have this lines in my code. Also i have put your sample code to get custom views but i have this error

For Each v As B4XView In CallBack
src\mycombobox\views\mycombobox.java:576: error: incompatible types: B4XViewWrapper cannot be converted to IterableList
final anywheresoftware.b4a.BA.IterableList group6 = _callback;


i try to use somethink like this

B4X:
' Check CallBack Type
If CallBack Is B4XView Then

    ' Create a object type from CallBack
    Dim vParent As B4XView = CallBack

    ' Try to find other Controls
    For Each v As B4XView In vParent
        If v.Tag Is MyComboBox Then
            Dim mc As MyComboBox = v.Tag
            mc.Hide
        End if
    Next

else
    ' Other type ...
End if

v.Hide cant use because the (Hide) sub is custom and must be mc.Hide

Thanks
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Hi,
You have missed a key method on line 8

your code should read:
B4X:
' Check CallBack Type
If CallBack Is B4XView Then

    ' Create a object type from CallBack
    Dim vParent As B4XView = CallBack

    ' Try to find other Controls
    For Each v As B4XView In vParent.GetAllViewsRecursive
        If v.Tag Is MyComboBox Then
            Dim mc As MyComboBox = v.Tag
            mc.Hide
        End if
    Next

else
    ' Other type ...

The ".GetAllViewsRecursive" will generate the IterableList that the For Each command is expecting
 
Upvote 0

dws

Member
Licensed User
Longtime User
Thanks Andrew.

I have this < .GetAllViewsRecursive > ( i miss to write there ).
With this i have a error message :

java.lang.ClassCastException: java.lang.Class cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:101)
at anywheresoftware.b4a.objects.B4XViewWrapper.asPanelWrapper(B4XViewWrapper.java:104)
at anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive(B4XViewWrapper.java:304)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at mycombo.views.mycombobox._close_popups(v4xcombobox.java:550)
at mycombo.views.mycombobox._btnopen_click(v4xcombobox.java:511)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5246)
at android.widget.TextView.performClick(TextView.java:10626)
at android.view.View$PerformClick.run(View.java:21256)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
 
Upvote 0
Top