B4J Question Writing views in lists to file. How?

Marc De Loose

Member
Licensed User
Longtime User
Hi,

I am trying to write a list containing custom views to a file.
File.WriteList("./", "Test.txt", lst_xRotateKnobs)
lst_xRotateKnobs = File.ReadList("./", "Test.txt")

does not give the correct results.

What is the best way to save my list containing customview (class module)?

thx
 

Marc De Loose

Member
Licensed User
Longtime User
Tried this:
B4X:
Dim kvs As KeyValueStore
    kvs.Initialize("./","test.dat")
    kvs.Put("1",lst_xRotateKnobs)
lst_xRotateKnobs is a list
But it gave me a java error (keyvaluestore). Cannot serialize object.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
kvs should put an object for list.

B4X:
kvs.PutObject("1",lst_xRotateKnobs)
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
Which version is the kvs you are using?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I am trying to write a list containing custom views to a file.
What do you mean? What does lst_xRotateKnobs contain? I guess xRotaryKnob views. If so, I don't think you can do that.
You can save data about the views, their state. You could create a custom type (declared in B4XMainPage or Main Activity) and use serialization to save the variable of this type, even a List of containing variables of this type.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4J example attached (TextFields instead of xRotaryKnobs but the concept is the same)
 

Attachments

  • SaveListOfValues.zip
    4.4 KB · Views: 13
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What is the best way to save my list containing customview (class module)?
You can not store Objects or read Objects back.

All you can do is to save the data you need to create a new instance of the Object and create a new instance setting all values that you have set before.

See LucaMS Answers about a customtype you can use to realize it.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…