B4A Library [Class] Flexible Table

Discussion in 'Additional libraries, classes and official updates' started by melamoud, Jun 30, 2013.

  1. klaus

    klaus Expert Licensed User

    You can set the two variables sortedCol and sortingDir to Public instead of Private in lines 313 and 314.
    Code:
    Public sortingDir As Int = 0 ' -1,0,1 as acc, unsorted, dec
    Public sortedCol As Int = -1' hold the sorted column -1 for none
    Add a Table1_HeaderClick event in you routine there you can get the sortingDir value.
    Code:
    Sub Table1_HeaderClick(col As Int)
        
    Log (col & " / " & Table1.sortingDir)
    End Sub
     
    Seneca likes this.
  2. Seneca

    Seneca Active Member Licensed User


    Perfect. It is solved
     
  3. Seneca

    Seneca Active Member Licensed User

    Hi,

    I've verified that when sorting columns, cells that start with accented vowels are not placed correctly.

    In the following example, Africa should appear in the first row.

    Screenshot_2018-07-15-13-22-13-759_b4a.TableDemo226.png
     
  4. klaus

    klaus Expert Licensed User

    Unfortunately, that's how CompareTo works.
     
    Seneca likes this.
  5. Seneca

    Seneca Active Member Licensed User


    Ok, thanks.
     
  6. klaus

    klaus Expert Licensed User

    Hi Seneca, can you please try the attached version 2.27 ?
     

    Attached Files:

  7. Seneca

    Seneca Active Member Licensed User

    Hi,

    I have tested version 2.27 and it works fine. But, in case the table has enough rows (more than 400) and each cell has a string of about 40 characters, the process becomes very slow.

    I will try to work exclusively with non-accented characters.


    In relation to the variables sortedCol and sortingDir as Public works perfect.

    Thanks for the help.
     
  8. klaus

    klaus Expert Licensed User

    I, somehow, suspected this.
     
  9. Dave61

    Dave61 Member Licensed User

    Is it possible to add this table to a panel that is added programmatically?

    I have an existing application which uses 3 tab pages, each with a panel in them.
    I now need to add this table to one of 3 panels.
    is that possible?

    p3.AddView(tblTraining, 0, 0, p3.Width, p3.Height) doesn't work and
    tblTraining.AddToActivity(Activity, 0, 0, p3.Width, p3.Height) doesn't work.

    My hope is that I don't have to pull the whole application apart to add in this last table.
     
  10. klaus

    klaus Expert Licensed User

    You have the AddToView method.
    Code:
    Sub AddToView(v As View, Left As Int, Top As Int, Width As Int, Height As Int)
    v can be either an Activity or a Panel.
    You may have a look at the demo program where a Table is added onto the Activity.
    Adding a table onto a Panel is the same.
     
    Johan Hormaza and Dave61 like this.
  11. Dave61

    Dave61 Member Licensed User

    Oh, that was embarrassingly simple!
    I was playing with that demo for ages but didn't notice that.
    Thank you Klaus.
     
  12. tufanv

    tufanv Expert Licensed User

    I have used the very early versions of this class long ago , I am impressed by how this class is developed over time. Thanks Klaus !
     
  13. Pencil3

    Pencil3 Member Licensed User

    I don't see a way to set a typeface for the Header unless I've completely overlooked it. Would it be possible to have the Header typeface bold using either CSBuilder or RichString? I have started to try to use CSBuilder but have not had much success.
     
  14. klaus

    klaus Expert Licensed User

    Not yet, I will have a look at it during the next days.
     
    Pencil3 likes this.
  15. klaus

    klaus Expert Licensed User

    Can you test the attached project?
     

    Attached Files:

    Johan Hormaza and Pencil3 like this.
  16. Pencil3

    Pencil3 Member Licensed User

    Tested and works! Thank you for adding SetHeaderTypeFaces.

    I do see the below with 2_28:
    Code:
    ** Service (starter) Start **
    ** 
    Activity (main) Create, isFirst = true **
    Class 
    not found: b4a.example.table, trying: b4a.TableDemo228.table
    event received NL80211_CMD_VENDOR, vendor_id = 0x1374, subcmd = 0xd
    ** 
    Activity (main) Resume **
    Unexpected 
    event (missing RaiseSynchronousEvents): sv_scrollchanged
    Check the unfiltered logs 
    for the full stack trace.
    java.lang.Exception: Stack trace
        at java.lang.Thread.dumpStack(
    Thread.java:1348)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:314)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:255)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    144)
        at flm.b4a.scrollview2d.ScrollView2DWrapper$MyScrollView.onScrollChanged(SourceFile:
    192)
        at android.view.View.scrollTo(
    View.java:16123)
        at flm.b4a.scrollview2d.TwoDScrollView.scrollTo(SourceFile:
    1680)
        at flm.b4a.scrollview2d.ScrollView2DWrapper.setVerticalScrollPosition(SourceFile:
    134)
        at b4a.TableDemo228.table$ResumableSub_JumpToRowAndSelect.resume(table.java:
    902)
        at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:
    48)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:732)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:348)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:255)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    144)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    176)
        at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:
    43)
        at anywheresoftware.b4a.keywords.Common$
    13.run(Common.java:1690)
        at android.os.Handler.handleCallback(Handler.java:
    873)
        at android.os.Handler.dispatchMessage(Handler.java:
    99)
        at android.os.Looper.loop(Looper.java:
    193)
        at android.app.ActivityThread.main(ActivityThread.java:
    6718)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:
    493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    858)


     
    Last edited: Jan 1, 2019
  17. Erel

    Erel Administrator Staff Member Licensed User

    Note that this is a warning, not an error. In many cases it will not do any harm. Test it in release mode.
     
  18. klaus

    klaus Expert Licensed User

    @Pencil3
    I see it too and have seen it in previous versions.

    @ Erel,
    The warning is raised in this line SV.VerticalScrollPosition = Row * cRowHeight in the routine below in the class code:
    The calling routine, in Main is Table1.JumpToRowAndSelect(30, 4)
    SV is a ScrollView2D object.
    Code:
    'Makes the given row visible and set it's row and colum as selected.
    Public Sub JumpToRowAndSelect(Row As Int, Col As Int)
        
    Dim rc As RowCol
     
        rc.Row = Row
        rc.Col = Col
        SelectRow(rc)
        Sleep(
    0)

        SV.VerticalScrollPosition = Row * cRowHeight
        
    Private i, Left As Int
        
    If Col > 0 Then
            
    For i = 0 To Col - 1
                Left = Left + ColumnWidths(i)       
            
    Next
        
    End If
        SV.HorizontalScrollPosition = Left
    End Sub
    Without Sleep(0), no warning, but SV.VerticalScrollPosition = Row * cRowHeight and SV.HorizontalScrollPosition = Left are not executed.
    I had replaced DoEvents by Sleep(0) last year.

    I got also a warning some days ago with AnotherDatePicker.
    I added this rouitne in the class code and got the warning calling AnotherDatePicker1.Refresh:
    Unexpected event (missing RaiseSynchronousEvents): datefield_textchanged
    Code:
    'Refreshs the date display, useful after a DateFormat change in the code.
    Public Sub Refresh
        DateField.Text = 
    DateTime.Date(selectedDate)
    End Sub
    Then I replaced it by:
    Code:
    'Refreshs the date display, useful after a DateFormat change in the code.
    Public Sub Refresh
        DateField_TextChanged(
    ""DateTime.Date(selectedDate))
    End Sub
    And the warning disappeared.

    The datefield_textchanged event is called in the routine:
    Code:
    Private Sub DateField_TextChanged (Old As String, New As String)
        
    Dim ticks As Long = GetCurrentDateFromTextField (New)
        
    If ticks <> INVALID_DATE Then
            setDate(ticks)
            dateField.SetColorAndBorder(dateField.Color, 
    2dip0xFFA1A1A10)
            
    If SubExists(CallBack, EventName & "_DateChanged"Then
                
    CallSub2(CallBack, EventName & "_DateChanged", ticks)        
            
    End If
        
    Else
            dateField.SetColorAndBorder(dateField.Color, 
    2dip, xui.Color_Red, 0)
        
    End If
    End Sub
    It seems that the warning is raised when:
    - a property in the class is changed.
    - and this property change raises an internal event in the class.
    - and the internal event routine calls an external event routine.
    - and #Event: xxx and #RaisesSynchronousEvents: xxx are declared.
     
    Last edited: Jan 2, 2019
  19. Erel

    Erel Administrator Staff Member Licensed User

    There are cases with TextChanged that you cannot remove this warning. If the app works fine in debug mode and release mode then you should document this and developers should ignore it.
     
    Pencil3 and klaus like this.
  20. klaus

    klaus Expert Licensed User

    I suppose that the comment is also valid for Resumable subs, like in the Table class with Sleep(0), code at the beginning in post#858.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice