Gridline in Tableview using scrollview

Discussion in 'Android Questions' started by junaidahmed, Feb 4, 2011.

  1. junaidahmed

    junaidahmed Well-Known Member Licensed User

    As I am using Tableview to display record like grid format,it works fine but only thing is no grid line.pls advise how to use gridline for tableview using scrollview
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not simple to implement. You will need to use a Canvas object and draw the lines between the labels. In order for it to work you should start drawing after adding all the rows.
     
  3. klaus

    klaus Expert Licensed User

    Attached you have a modified version of the TableExample program with row and column lines.
    The line color is the ScrollView.Panel.Color.
    So the row and column line colors are the same.
    The line width can be set in the ColLineWidth and RowLineWidth variables.
    The lines are generated by shifting the lables by the line width. That means that the Label.Width is equal to the column width minus the line width and the same for the height.

    Best regards.
     

    Attached Files:

    Last edited: Feb 4, 2011
    sorheim likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    This is a great solution! Much better than my suggestion..
     
  5. klaus

    klaus Expert Licensed User

    Thank's Erel.
    I would suggest to replace the original example program in the 'Creating a table view based on ScrollView' tutorial.

    Best regards.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I will add a link to this post.
     
    zabayin likes this.
  7. barx

    barx Well-Known Member Licensed User

    Ok, time for me to give this a go. I need to create multiple tables on different activity screens (only ever one per screen). Had a look at the code and think I can figure out the usage. My question is, can most of this code by added to a code module and called. Would it just be a matter of adding all but the process globals and activity_create to the code module (called 'table' for now) and then calling table.LoadTableFomCSV(File.DirAssets, CSVListName.csv, true).

    Hope this can be done as it will mean I wont have to add all the subs to each activity I need a table on. Thanks.
     
  8. barx

    barx Well-Known Member Licensed User

    This will probably be fround upon, but I could do with knowing if this is possible so...... bump
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You can convert the code to use a module. In fact the original code doesn't use code modules because it was released before those were supported.
     
  10. magarcan

    magarcan Active Member Licensed User

    I'm working over example v1.2, but I have some problems:
    1. How can I change of each one of the columns?
    2. Can I show images or links inside grid?
    3. I'm using Latin characters inside de CSV file, but they aren't showed well.
    4. How can I convert code to a module?

    Thanks!
     
    Last edited: Aug 21, 2011
  11. magarcan

    magarcan Active Member Licensed User

    An other question. Can I set up different actions for different cells??
    Thanks!!
     
  12. magarcan

    magarcan Active Member Licensed User

    Anyone?
     
  13. klaus

    klaus Expert Licensed User

    You could have a look at this thread where you find lots of ScrollView examples.
    1) Have a look at this example ScrollView example with multiselection and SQL
    2) Images yes. Links, I have never tried it but should be possible.
    3) You should save your csv file with UTF-8 encoding.
    Otherwise you could use TextReader with ISO-8859-1 encoding, but you must read each line and separate the entries yourself.
    4) You can only do it in a Code Module. You should try doing it.

    Best regards.
     
  14. Gearcam

    Gearcam Active Member Licensed User

    colum widths

    is it possible to have different width colums ?

    Steve
     
  15. klaus

    klaus Expert Licensed User

  16. cbal03

    cbal03 Member Licensed User

    Great examples and thorough explanations!

    Hello Klaus,
    Just wanted to say thank you.

    The cell dividing lines give a very clean look too!

    :sign0087:
     
  17. Kristofferson

    Kristofferson New Member Licensed User

    Sorting

    Hi, i'm a new member of this forum. I recently purchased B4A and i'm having a great time using it. :)
    I've been reading the forum and found so many helpful tips. Then i stumbled with this thread which is what i need.

    I do have a question. Is column sorting possible for this TableView?

    I'm looking into sorting the CSV data first before loading in the TableView but not sure if will be is faster/efficient as it will need to clear and reload all csv data.

    Can you provide a better solution for this?

    Thanks!

    :sign0163:
     
  18. klaus

    klaus Expert Licensed User

    There is no column sort implemented.
    If you want sort columns it would be much more efficient to use a SQLite database instead of a csv file.
    An example is in this thread SQLiteDB.

    Best regards.
     
    Last edited: Jun 9, 2014
  19. nemethv

    nemethv Member Licensed User

    Hi,

    I'm trying to get to define the colour of the cell based on the content of another cell in the same row.

    This is the code as it was in the SQL tutorial, exc for one line that I added:
    Code:
    Sub GetView(Row As Int, Col As Int) As Label
    ' Returns the label in the specific cell
       Dim L As Label
       L = Table.GetView(Row * NumberOfColumns + Col)
       
    Return L
    End Sub

    Sub AddRow(Values() As String)
    ' Adds a row to the table
       Dim ColWidth As Int
       
       
    If Values.Length <> NumberOfColumns Then
          
    Log("Wrong number of values.")
          
    Return
       
    End If
       ColWidth=
    0
       
    For i = 0 To NumberOfColumns - 1
          
    Dim L As Label
          L.Initialize(
    "cell")
          L.Text = Values(i)
          L.Gravity = Alignment(i)
          L.TextSize = FontSize(i)
          L.TextColor = FontColor(i)
          L.Color=CellColor(i)
          
    Dim rc As RowCol
          rc.Initialize
          rc.Col = i
          rc.Row = NumberOfRows
          L.Tag = rc
          Table.AddView(L, ColWidth, RowHeight * NumberOfRows, ColumnWidth_1(i), RowHeight_1)
          ColWidth=ColWidth+ColumnWidth(i)
          
    If i = 0 AND GetView(rc.Row,1).Text = "Something" Then L.Color = Colors.Red 
    'this is what I added. Basically, for Col0 only, if the cell after (same row, Col1) says "something", 
    'I want Col0's cell to be red for that line, otherwise stay as predefined. However when I use this 
    'construct, it tells me View should be initialised first. And I'm not too sure it will work anyway.
       Next
       
       NumberOfRows=NumberOfRows+
    1
       Table.Height = NumberOfRows * RowHeight
    End Sub
    Thanks!
     
  20. mc73

    mc73 Well-Known Member Licensed User

    I see that a) you didn't initialize the label 'L' in the subroutine and
    b) even if you did, I don't see how you could read a latest label, since you write it after you write label0.

    I think you should change the for loop as follows:
    Code:
    For i = numberOfColumns-1 To 0 step -1
    and then avoid the subroutine, by changing line
    Code:
    If i = 0 AND GetView(rc.Row,1).Text = "Something" Then L.Color = Colors.Red
    to
    Code:
    If i = 0 AND Table.GetView(rc.Row * NumberOfColumns + 1).Text = "Something" Then L.Color = Colors.Red
    and placing it above line
    Code:
    Table.AddView(L, ColWidth, RowHeight * NumberOfRows, ColumnWidth_1(i), RowHeight_1)
     
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