Android Question How to check type of views are there in the activity? In the example,he knows that he has what type of views are.

Theera

Well-Known Member
Licensed User
Longtime User
refer to this I have test the example StateManager in B4A. I think it is useful for multi platforms B4A,B4J,and B4i. unfortunately,I'm not good at coding.
how to convert it to be B4xlib file. Who could help me to do that?

Best Regards,
Theera
 

Theera

Well-Known Member
Licensed User
Longtime User
Converting .bas file to .b4xlib is just as easy as add the file as a .zip file.

To save data, there are also many alternatives such as KVS and File.WriteMap.
How to check type of views are there in the activity? In the example,he knows that he has what type of views are.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
B4X:
    Log(GetType(v))
I'm sorry my terrible English. I don't know : Are there types of views in activity? How to code in Do while Loop of each type of views?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I'm sorry my terrible English. I don't know : Are there types of views in activity? How to code in Do while Loop of each type of views?
you can do it like this:

B4X:
    For Each v As View In Activity.GetAllViewsRecursive
        Log(GetType(v))
    Next

this will loop through all the views in your activity.
you can also do it for a single panel that holds many views.
 
Upvote 0

emexes

Expert
Licensed User
B4X:
Log(GetType(v))

Can also check for types directly eg:

B4X:
For Each v As View In Activity.GetAllViewsRecursive
    If v is Button Then
        Log("Press that Button! ?")
    Else If v Is CheckBox Then
        Log("Tick that Box! ✔️")
    Else If v Is TextField Or v Is TextArea Then
        Log("Write that Text! ✍️")
    Else
        Log("I don't recognise " & GetType(v))
    End If[
Next
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Can also check for types directly eg:

B4X:
For Each v As View In Activity.GetAllViewsRecursive
     If v is Button Then
        Log("Press that Button")
    Else If v Is CheckBox Then
        Log("Tick that Box")
    Else If v Is TextField Or v Is TextArea Then
        Log("Type that Text")
    Else
        Log("I don't recognise " & GetType(v))
    End If[
Next
In example,he used that code strategy,but each view I must code all of views for supportted. (My English can't expain my thinking).
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
In example,he used that code strategy,but each view I must code all of views for supportted. (My English can't expain my thinking).
You don't need to store the state of all views. If you use B4XPages, you don't even need to store anything.
Before B4XPages era, maybe you only want to store the value entered in a text field when you navigate to other activity and load this value when you return but this is no longer a thing now.
 
Upvote 0
Top