Android Question Get all views in Tabstrip

warayTek

Member
Licensed User
Hello everyone, I'm trying to get all views in a tabstrip

I am getting a null return, using the code below.
B4X:
Private Sub getFieldsInfo(findtag As String) As String
    Dim lbl As Label
    For Each v As View In Panel1.GetAllViewsRecursive ' txtAccntNum
    
        If v Is Label  Then
            lbl = v
            If v.tag = findtag Then
                Log(v.tag)
                Dim mdata As String
                mdata = lbl.Text
                Log(mdata)
                Return mdata
            End If
        End If
    Next
    Return False
End Sub
Thank you for your time.
 

Sagenut

Expert
Licensed User
Longtime User
I think because you are mixing between "v" and "label".
After assigning "v" to "lbl" you should refer only to "lbl".
Try this
B4X:
Private Sub getFieldsInfo(findtag As String) As String
    For Each v As View In Panel1.GetAllViewsRecursive ' txtAccntNum
   
        If v Is Label  Then
            Dim lbl as Label
            lbl = v
            If lbl.tag = findtag Then
                Log(lbl.tag)
                Dim mdata As String
                mdata = lbl.Text
                Log(mdata)
                Return mdata
            End If
        End If
    Next
    Return False
End Sub
 
Upvote 0

warayTek

Member
Licensed User
Hello, I get the following error:
B4X:
Logger connected to: 055542508O000936
--------- beginning of crash
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
main_getfieldsinfo (java line: 410)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
    at b4a.example.main._getfieldsinfo(main.java:410)
    at b4a.example.main._mnu1_click(main.java:446)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA$1.run(BA.java:360)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:264)
    at android.app.ActivityThread.main(ActivityThread.java:7581)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Remove the
B4X:
Return False
I forgot it.
Or change it with
B4X:
Return ""
to have an empty string in return if nothing is found.
 
Upvote 0

warayTek

Member
Licensed User
Thank you for the time, but unfortunately, I still have the same error:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
main_getfieldsinfo (java line: 410)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
    at b4a.example.main._getfieldsinfo(main.java:410)
    at b4a.example.main._mnu1_click(main.java:446)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA$1.run(BA.java:360)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:264)
    at android.app.ActivityThread.main(ActivityThread.java:7581)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Please post a project that show the issue to check it better.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I am not used to TabStrip so I could not have done the best/correct method.
Your issue was that you have Panel1 as base panel in all pages.
Using Panel1 as target it will reference the last one added, so Page 3.
I renamed the panels on the 3 pages as Panel1, Panel2, Panel3.
Then I declared another panel, currentpanel, that will reference the right one when changing page.
Check the code.
 

Attachments

  • TabStrip.zip
    17.7 KB · Views: 35
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…