B4A Library [Class] Flexible Table

Espinosa4

Active Member
Licensed User
Longtime User
Good morning klaus!
The new version works fine! Many many thanks for your work and for your time!

Best regards,
Espinosa
 

Mike Olmsted

Member
Licensed User
Longtime User
Okay, I am starting to be a believer but........................

table1.SetColumnsWidths(Array As Int(60dip,170dip,60dip,60dip,120dip,00dip,00dip))

doesn't work anymore, need to set column width at 2 or more.
 

Mike Olmsted

Member
Licensed User
Longtime User
The problem only occurs after a table refresh ( like after an edit). Try my refresh button.
 

Attachments

  • table28Refresh.zip
    40.6 KB · Views: 411

elitevenkat

Active Member
Licensed User
Longtime User
Hi Klaus
I do not have b4a v.3 but 2.71 When I tried it say version conflict. Do I have to upgrade or do you have (sample) for v 2.71 for me test.
 

Mike Olmsted

Member
Licensed User
Longtime User
Hi Klaus
I do not have b4a v.3 but 2.71 When I tried it say version conflict. Do I have to upgrade or do you have (sample) for v 2.71 for me test.

Just make sure you extract all......then say okay a couple times...and compile in 2.71.....
 

HARRY

Active Member
Licensed User
Longtime User
Looking for simple example.

Hi, recently I have made a serious start with Basic4Android; I have been using Basic4PPC for many years. Now I am converting some 'old' programs. In Basic4PPC I use a KML file by reading it line by line, analyzing the contents and storing each collection of data of an object in a multi column (13) table, columns having a header and many columns with column width set to 0.

I can find examples of using CSV files or data bases, but not what is necessary to define the table , the columns, etc and adding rows. I understood that the complete KML file has to be read into a list and that that list can be operated upon line by line; that works well. May be that I am thinking still too much in Basic4PPC.

Can somebody help me.

Harry
 

HARRY

Active Member
Licensed User
Longtime User
Hallo Erel,
This is the code of the program:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim KMLPath As String
    Dim KMLFile As String
    Dim TextLine As String
    Dim FirstLine As String
    Dim SecondLine As String
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim POITable As Table
    Dim PanelForTable As Panel
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("KMLtest")
   
    PanelForTable.Initialize("")
    Activity.AddView(PanelForTable, 20dip, 20dip, 100%x - 40dip, 100%y - 90dip)
   
    POITable.Initialize(Me, "POITable", 15, Gravity.CENTER_HORIZONTAL, True)
    POITable.CellAlignment = Bit.OR(Gravity.LEFT, Gravity.CENTER_VERTICAL)
    POITable.HeaderColor = Colors.Blue
    POITable.HeaderTextColor = Colors.Yellow
    POITable.TextColor = Colors.Blue
    POITable.TableColor = Colors.Red
    POITable.AddToActivity(PanelForTable, 0, 0, PanelForTable.Width, PanelForTable.Height)   
    POITable.SetColumnsWidths(Array As Int(0,0,0,0,0,0,0,0,0,0,0,0,0,0,100))
    KMLFile = "IGO.kml"
    KMLPath="/storage/extSdCard/iGo/content/userdata/poi/"
    ReadKML
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ReadKML
Dim State
Dim GroupName
Dim POIF
Dim POII
Dim POIGroup
Dim POIName
Dim POIDescription
Dim POIComment
Dim POISurface
Dim POITelephone
Dim POIPhoto1
Dim POIPhoto2
Dim POIPhoto3
Dim POILongitude
Dim POILatitude
Dim POIVisits
Dim POIWWW
Dim TempLine As String
Dim ToModStr As String
Dim Pos As Int
Dim CurrentGroup As String
Dim POIList As List
Dim i As Int
Dim XMLStr As String
Dim KMLStr As String
    XMLStr="<?xml"
    KMLStr="<kml"
    File.OpenInput(KMLPath,KMLFile)
    POIList=File.ReadList(KMLPath,KMLFile)
    TempLine=POIList.Get(0)
    TextLine=TempLine.Trim
    TempLine=TextLine.SubString2(1,6)
    If TempLine <> XMLStr Then
        BadKml
    Else
        FirstLine=TextLine
    End If
    TempLine=POIList.Get(1)
    TextLine=TempLine.Trim
    If TextLine.SubString2(0,4) <> KMLStr Then
        BadKml
    Else
        SecondLine=TextLine
    End If
    For i = 2 To POIList.Size-1
        TempLine=POIList.Get(i)
        TextLine=TempLine.Trim
        If TextLine.Contains("<Folder>") Then
            State=1
        Else If TextLine.Contains("<name>") Then
            If State =1 Then               
                CurrentGroup=TextLine.SubString2(6,TextLine.Length-7)
                'GroupsTable.AddRow(CurrentGroup)
            Else If State=2 Then
                POIGroup=CurrentGroup
                POIName= TextLine.SubString2(6,TextLine.Length-7)
            End If
        Else If TextLine.Contains( "<Placemark>") Then
            State =2
            POIF=""
            POII=""
            POIGroup=""
            POIName=""
            POIDescription=""
            POIComment=""
            POIPhoto1=""
            POIPhoto2=""
            POIPhoto3=""
            POILongitude=""
            POILatitude=""
            POIVisits=""
            POISurface=""
            POITelephone=""
            POIWWW=""
           
        Else If TextLine.Contains( "<phoneNumber>")  Then
            POITelephone= TextLine.SubString2(13,TextLine.Length-14)
        Else If TextLine.Contains("<description>") Then
            POIDescription=TextLine.SubString2(22,TextLine.Length-17)
        Else If TextLine.Contains( "<Data name=" & Chr(34) & "Surface" & Chr(34) & "><value>") Then
            POISurface=TextLine.SubString2(28,TextLine.Length-15)
        Else If TextLine.Contains("<Data name=" & Chr(34) & "Comment" & Chr(34) & "><value>")  Then
            ToModStr=TextLine.SubString2(28,TextLine.Length-15)
            POIComment=ToModStr.Replace(Chr(95)& Chr(95) , Chr(13) & Chr(10))
            ToModStr=POIComment
            POIComment=ToModStr.Replace("/_", "_")
        Else If TextLine.Contains("<Data name="& Chr(34)& "Photo1" & Chr(34) & "><value>") Then
            POIPhoto1=TextLine.SubString2(27,TextLine.Length-15)
            POIF="*"
        Else If TextLine.Contains("<Data name="& Chr(34)& "Photo2" & Chr(34) & "><value>")Then
            POIPhoto2=TextLine.SubString2(27,TextLine.Length-15)
            POIF="*"
        Else If TextLine.Contains("<Data name="& Chr(34)& "Photo3" & Chr(34) & "><value>") Then
            POIPhoto3=TextLine.SubString2(27,TextLine.Length-15)
            POIF="*"
        Else If TextLine.Contains("<Data name="& Chr(34)& "Visits" & Chr(34) & "><value>") Then
            POIVisits=TextLine.SubString2(27,TextLine.Length-15)
        Else If TextLine.Contains("<Data name="& Chr(34)& "WWW" & Chr(34) & "><value>") Then
            POIWWW=TextLine.SubString2(24,TextLine.Length-15)
            POII="*"
        Else If TextLine.Contains("<coordinates>") Then
            Pos=TextLine.IndexOf2( ",",0)
            POILongitude=TextLine.SubString2(13, Pos)
            POILatitude= TextLine.SubString2(Pos +1, TextLine.Length- 15)       
        Else If TextLine.Contains("</Placemark>")    Then
            POITable.AddRow(Array As String(POIDescription,POIPhoto1,POIPhoto2,POIPhoto3,POIComment,POILongitude,POILatitude,POIVisits,POIGroup,POISurface,POITelephone,POIWWW,POIF,POII,POIName))
        Else If TextLine.Contains("</Folder>") Then
            If State=3 Then
                Exit
            Else
                State=3
            End If
        End If   
    Next
    'FileClose(KML)
    'KMLMod=False
    'GroupsTable.TableSort("Groepen ASC")
    'GroupsTable.Visible=True
    'T4Ignore=True
End Sub

Sub BadKml
    Msgbox ("Foutief begin KML bestand", "KML")
    Activity.Finish
   
End Sub


If more convenient for you I could also mail the code and the file to be loaded into the table.

Regards,

Harry
 

HARRY

Active Member
Licensed User
Longtime User
Hi Erel,

The program does not reach AddRow. It halts on line 191 of the Table module in the Sub SetColumnWidths with as LastException: java.langRuntimeException: Object should first be initialized(View).

Harry
 

HARRY

Active Member
Licensed User
Longtime User
Hallo Klaus,
Please find attached a .zip file containing the program and the file. I did some more tests: TableV1_29.b4a supplied with the table module runs well as it is. However, when I insert after Table1.AddToActivity(pnlTable, 0, 0, pnlTable.Width, pnlTable.Height) a line with
the text Table1.SetColumnsWidths(Array As Int(10dip,10dip,10dip,10dip)) the program reports the same error .

I do hope that I am not putting you and Erel at work because of a stupid error of me.

Regards,

Harry
 

Attachments

  • KMLTest.zip
    25.6 KB · Views: 382

klaus

Expert
Licensed User
Longtime User
Here you are.
You missed adding the headers !
In your ReadKML routine you Dim a lot of variables without the type specification.

But I don't understand why filling a table with 15 columns and showing only 1 ?
 

Attachments

  • KMLTest_1.zip
    30.5 KB · Views: 370

HARRY

Active Member
Licensed User
Longtime User
Hallo Klaus,

Thanks!

I did't find that I had to add headers and as I was not interested in headers ......

I understood that String is the default type in Basic4Android.

The visible column is the one used to select an item ; then the program, in Basic4PPC 8 Forms, uses all other data of the selected row. Now I have to find another solution as the table is only accesssable in one Activity. May be the best way is to copy the table, after sorting, into an array of types in Process Globals. The table is not that large.

Regards,

Harry
 

lhbrito

Member
Licensed User
Longtime User
How can I resize (or move) the table after AddToActivity?

explaining:
On my screen I will use two tables, the first by default is on top and the second at the bottom.
I want to let the user change the visibility of these tables.
(example: if the first table to be invisible, the second has to occupy the entire screen ...)

Is it possible?

Thanks!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…