Android Question Why "Dim clv As CustomListView = Activity.GetView(0).tag" not work?

Filippo

Expert
Licensed User
Longtime User
Hi,

Why this line code (see title) does not work(see error message)?
But the line code "Dim btn As Button = Activity.GetView(1)" yes?
With other customview it works too.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    Dim clv As CustomListView = Activity.GetView(0).tag
    Log("clv.IsInitialized=" & clv.IsInitialized)
    
    Dim btn As Button =  Activity.GetView(1)   
    Log("btn.IsInitialized=" & btn.IsInitialized)
End Sub

error message:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 353)
java.lang.ClassCastException: java.lang.String cannot be cast to b4a.example3.customlistview
at b4a.example.main._activity_create(main.java:353)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at b4a.example.main.afterFirstLayout(main.java:105)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7880)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:568)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
 

Attachments

  • Test3.zip
    9.3 KB · Views: 58
Solution
The reason that the discussed standard wasn't implemented in xCLV is that it isn't a backward compatible change. Apps might rely on the Tag property being Null or empty.

Alexander Stolte

Expert
Licensed User
Longtime User
Because in the tag is not the xclv. The solution:
 
Upvote 1

Filippo

Expert
Licensed User
Longtime User
Because in the tag is not the xclv. The solution:
Yes, this can be a solution, but why an extra solution only for the xCustomListview?
With all other customviews it works without problems.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
With all other customviews it works without problems.
All other CustomViews that were either updated to this new standard, or were created after 20. May 2020 this became standard. And the xCLV is not one of them.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
All other CustomViews that were either updated to this new standard, or were created after 20. May 2020 this became standard. And the xCLV is not one of them.
I can live with this without problems, but what's wrong with standardizing the xCustomListview? Is there a technical problem I don't know about?

I myself try to standardize all my own customviews, I think this is normal.
 
Upvote 0
Top