Android Question How do I save and load Scrollview (labels) with a text file?

Bryan

Member
Licensed User
Longtime User
I am using this example ScrollViewList.zip from Klaus and would like to know how to save and load the scrollview list to a text file. I don't want to use a SQL database as it seems to be overkill just for a scrollview with labels. I'm not sure how to get the text from the labels in the scrollview panels. If I could I would just save and load the text as a list from a text file. Help would be appreciated. Thanks

OK, I think I have it now using
GetItemView(i).Text to get the contents of the text contents of the Labels

Well, I guess that won't exactly work as I get an error
java.lang.RuntimeException: Object should first be initialized (View).

This is the sub I created to save the list to a file but it is giving me the above error.

B4X:
Sub WriteList
    Dim i As Int
    Dim List1 As List
    List1.Initialize
    For i = 1 To NumberOfRows
    List1.Add(GetItemView(i).Text)
    Next
    File.WriteList(File.DirRootExternal, "List.txt", List1)
End Sub

This is used with the ScrollViewList example provided by Klaus.
 
Last edited:

Bryan

Member
Licensed User
Longtime User
OK, I switched over to using Customlistview. It is much different then using ScrollViewList. Problem I'm now having is getting a panel to stay pressed after it is clicked on.
I found in another post you said to use something like this:
B4X:
Sub SetPressed(cmd As Button, Pressed As Boolean)
  Dim ref As Reflector
  ref.Target = cmd
    ref.RunMethod2("setPressed", Pressed, "java.lang.boolean")
End Sub

and, to use CallSubDelayed to set it from Panel_Click event.

I'm not sure what it is I'm doing wrong but I can't get this to work. Can you be more specific?

Is it that "SetPressed" only works with buttons?
 
Last edited:
Upvote 0

Bryan

Member
Licensed User
Longtime User
Please be more specific what you want to do. Make a loop over all views and save the content?
OK, maybe I am not explaining this the right way. In ScrollView when you select an item it stays highlighted until another item is selected. I want to accomplish the same thing in CustomListView because it does not behave the same as ScrollView. When you select an item in CustomListView it becomes highlighted (orange color) for a brief period of time.

Originally, I was using scrollview and had problems with sending the contents to a list. So, I switch over to CustomListView and now trying to get the problem I just mentioned solved pertaining to highlighting of items selected. Maybe I should have created a separate topic.
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Longtime User
As I see, all you want is to change the color (let's say highlight it). In your code it looks to me as if you want to use the "keypressed" event to do that which is suboptimal.

Could you describe what your app does? After that I will give you a simple example which explains how to add arrays of views and use them later.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…