Android Question StateManager and CustomListview

LucaMs

Expert
Licensed User
[Probably I should have written this post in "Bugs & wishlist"]

If I have not made any mistakes, it seems to me that StateManager can not rebuild (save & restore) CustomListviews (let alone xCustomListviews) and their contents.
 

LucaMs

Expert
Licensed User
It is expected
Do you mean that if I have a panel with an EditText inside it the text will not be saved & restored? I don't think (hope) so and a CLV is made of these components.

However, I think that xCLV is the most important View of B4X and that it is appropriate to study a way to make StateManager work even with it.
 

Harris

Expert
Licensed User
I think that xCLV is the most important View of B4X
+100

I think the real use of State Manager is to handle the orientation change. I nipped this by (on phones) locking my app to portrait.
However, I understand that this is not the only time the activity could be rebuilt... You could code a statemanager yourself - but that could get difficult.

My new app uses 95% xCLV. I use it even when the form does not need to scroll.
 

LucaMs

Expert
Licensed User
I think the real use of State Manager is to handle the orientation change. I nipped this by (on phones) locking my app to portrait.
My app is in landscape but my phone, if paused and activated again, changes for a moment to portrait and I don't know (if) is possible to avoid that even the app changes orientation (I don't think so).

I know that:
Do you mean that if I have a panel with an EditText inside it the text will not be saved & restored?
in this case StateManager does not creates the panel and with a CLV it should do it, to save its state, but I think that we can find a way.
 

Harris

Expert
Licensed User
if paused and activated again, changes for a moment to portrait
I have seen this as well. Seems phones (any device in general) force a portrait initially - then will respect your (its') orientation setting... Same with a tablet. You boot the tablet in landscape - it shows portrait until well booted - then it changes to landscape... Seems Android boots always to portrait - until told afterwards how to display - when it figures out how it is positioned. Guess it has to start somewhere - and portrait is pretty much assured.

With a simple form (activity), statemanager handles edittext well (and SOME other controls). However, xCLV is not that simple. Each item ( a separate panel ) in a CLV list is - in essence - a unique view. It (SM) shall need to know the index of the CLV and the types for each object it needs to store the values of....

Perhaps a clear example of how this confounds you may help in determining a solution - if any worth pursuing.

Like I said, you could build your own manager, storing each value for whatever anytime an edit is made (sql table, ini file, KVS ... then re-pop your xCLV on demand - which and when you determine ( ie. was not saved since last viewed ). Arduous I know - but such is life.... In the end - you get exactly what you are asking for (then publish it so we all can enjoy your hard earned cleverness).

Just a thought...

B4X:
Sub SetOro
 
' In every Activity Resume - this sub is called
' It ensures that the activity will not rotate on phones - in particular..
' My tablet devices are mounted in cradles in a landscape position (which is best use of a tablet)

' oro is a public var - set by the user OR forced by me...

    If oro = "Both" Then
        ph.SetScreenOrientation( - 1 )
    End If
 
    If oro = "Landscape" Then
        ph.SetScreenOrientation( 0 )
    End If
 
    If oro = "Portrait" Then
        ph.SetScreenOrientation( 1 )
    End If
 
End Sub
 
Last edited:

LucaMs

Expert
Licensed User
(then publish it so we all can enjoy your hard earned cleverness)
These times we should thinking in XUI mode :D.

I don't know if StateManger (wrote many years ago) works even with B4XViews; however, a new version of SM should be developed that can also rebuild an xCLV.

I can handle this in all my projects, without the need for MS, of course; but since SM exists, improving it would be a good thing.



The code you posted is not enough, unfortunately, because it will be executed when the change (orientation) is already happened.
It would be needed some settings to prevent the app from changing orientation, under any conditions, but I do not think this exists.
 

LucaMs

Expert
Licensed User
I don't know if StateManger (wrote many years ago) works even with B4XViews;
I don't know this because... I don't think enough :p (and I usually do not focus enough on new concepts-objects, I do not assimilate and do not memorize; I think it's mental laziness :D).

On layouts created by Designer, StateManger should work, since there are no B4AViews to add, just the usual Views.
 

Harris

Expert
Licensed User
These times we should thinking in XUI mode :D.
Yes, definitely. To code (think, develop otherwise) is a pure waste of your (my / our) time. We now have the power to cross platform with ease.
Let us promote / accelerate this and not look back. Extreme genius at work here and it (aka - he) needs our support - test / debug, enhance, suggest and carry forward.

a new version of SM should be developed
Go for it... You have the talent ( I think the original author is busy currently... Building stuff you and I could never fathom! ).

I think it's mental laziness
Yes, you are correct... Booze helps - but in moderation (personal limits accepted) ....

I meet new and clever people all the time here. They say they "stumbled upon" B4X by (some chance).

What they all agree on (or question) is first off: How is all this possible?
Second: Why is this so easy? (IDE, designer, Android AND iOS in same code base - WTF? )
Third: Why do I waste time in all other offerings?
Fourth: I can easily write web apps too?
Fifth: All my apps actually work (A, I, J)... Unheard of..
Sixth: I am hooked...

Then: They become a valuable part (resource) of our community - contributing to (source or suggestions) just like your original reach for help here.

Met one just 3 days ago...
Why? - Cause of you, I (and the big Er) along with everyone else here that make B4X better each day.

Again - show me something else better..... No one has ever replied to this challenge (posted many times) - and they would be hard pressed to do so.

Heck - if I had 1G for every time I made this statement - I could pay my bar tab for a year! (eh? eh? - anybody listening?);)

Anyways, for those who know me (and don't) - it is all in moderation (consumption and verbally).

Thanks.
 

Erel

Administrator
Staff member
Licensed User
I don't know if StateManger (wrote many years ago) works even with B4XViews
It works as there is no real difference between B4XView or View. They both wrap the same native views.

StateManager is not the right tool to save the state of xCLV.
Treat xCLV as a UI element, not a data store.
You should keep all the information related to each item and its state in a list of custom types.
It is then very simple to save this list with KVS2 and load it in Activity_Create.

See this related example: https://www.b4x.com/android/forum/t...ew-lazy-loading-virtualization.87930/#content
 

LucaMs

Expert
Licensed User
Thank you, Erel; I think that I know how to "solve" (your hint is very useful, of course).

Treat xCLV as a UI element, not a data store.
xCLV is an UI element, like EditText and the other views, of course (more complex and custom but it is an UI element).

Just because of this, as you use StateManager to save & retrieve the user input in an EditText, it would be very useful if StateManger could also save the contents / status of an xCLV (which is composed of EditTexts, CheckBoxes, ...).
 
Top