Android Question Displaying a large text (log) file

Indy

Active Member
Licensed User
Longtime User
Hi All,

I'd like to build a function to display the application's logfile. However, I don't know what is the best "view" to use. The logfile could be quite large so guess using a Label or Edit view will not work. I built a test function using a label inside a scrollview but that obviously the label has a height limit as the bottom half of the text is missing. Does anyone have any pointers on how best to achieve this?

Thanks
 

JohnC

Expert
Licensed User
Longtime User
You could just display the log file in a webview control, which will automatically provide scrolling ability.
 
Upvote 0

Quandalle

Member
Licensed User
You can also use a customListview
B4X:
private clv As CustomListView  ' declare by the designer

 
 Sub displayLog
    Dim List1 As List
    List1 = File.ReadList(PathLog, "log.txt")
    clv.Clear
    For i = List1.Size-1 To 0 Step -1 ' populate the list : last log events, at the top of list 
        clv.AddTextItem(List1.Get(i),Null)   
    Next
End Sub
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
You can also use a customListview
B4X:
private clv As CustomListView  ' declare by the designer


Sub displayLog
    Dim List1 As List
    List1 = File.ReadList(PathLog, "log.txt")
    clv.Clear
    For i = List1.Size-1 To 0 Step -1 ' populate the list : last log events, at the top of list
        clv.AddTextItem(List1.Get(i),Null)  
    Next
End Sub

Hi

This is not a bad idea. Seems to do what I need. However, noticed that the text wraps on physically smaller screens. Couldn't see anywhere in the settings of un-wrapping text. Not really a show-stopper. Thanks for helping.
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
You could just display the log file in a webview control, which will automatically provide scrolling ability.

I did think of that first but, wanted to avoid using the WebView because then you have to format the text in html to get it to look good. Thanks for the tip though.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I built a test function using a label inside a scrollview but that obviously the label has a height limit as the bottom half of the text is missing.
How did you set the height of the Label and the internal ScrollView.Panel?
I would have used this.
Maybe, you could have a look at THIS post.

Anyway, xCustomListview is based on a ScrollView.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I did think of that first but, wanted to avoid using the WebView because then you have to format the text in html to get it to look good. Thanks for the tip though.

Even if you use clv, you would still need to set the style/format of it.

Formatting text in webview is simple and allows for a nice feature to hilight errors:

B4X:
<!DOCTYPE html>
<html>
<body>

<p style="font-family:'Courier New'; font-size:11px">

[text from your log]

</p>

</body>
</html>

Your log file probably contains both events and errors in it. Using a webview can help highlight error lines.

For example, in your code, when you add an error line to the log file, you could make it noticeable by displaying it in red in the webview control using the font tag:

B4X:
<font color="red">This line is an error</font>

This way as you scroll through the log file, error's can be easily seen.
 
Upvote 0
Top