Android Question Flexible Table on TabHost

Discussion in 'Android Questions' started by Yafuhenk, Apr 10, 2015.

  1. Yafuhenk

    Yafuhenk Active Member Licensed User


    I spent many evenings trying to solve two issues and I can't solve it.
    Maybe you can help

    1) I can't see all columns when I add the flexible table to a tabhost.
    2) SQL totals not the same when I use with GROUP BY or without GROUP BY

    I wrote a demo program to show what I mean. The software creates a sales database and fills it with dummy data. Press on the customer button and you will see that not all the columns are completely visible. I can't find what I am doing wrong

    In the same software press on the salesmanager button and see that the totals shown in the headers differs sometimes a few Euro compared to the totals of the rows. I wrote a program for sales manager in .NT where the same query is used. There it is correct. Also here I can't find the error.

    I really hope that you are willing to have a look.

    Thanks in advance for your time spent

    Best regards Henk

    Attached Files:

  2. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Hi @YAFUHENK please see the screenshot of your demo app on my device...

    What is it that you want to achieve? I'm guessing that first of all you want the black panel and TabHost to fill the entire screen (my device, a Nexus 7 2103 is notorious for screwing up layouts, 1920x1104 scale=2 [320dpi]). This can easily be achieved using the designer scripts. However they're may be a bigger problem.
    I've spent quite a while trying to understand why the scroll doesn't work, to the point where I've installed the flexible table table class and modified the example to add the table onto a TabHost and it appears that the scroll events are not passing through to the class! Click events work but scrolling doesn't, unless I'm making the same mistake as you? I'm afraid it needs someone with more experience than me to solve this one. I just thought I'd post my findings so that someone else can follow on from here?
  3. Yafuhenk

    Yafuhenk Active Member Licensed User

    Thanks for your reply. I know about the script designer. That's not the issue. The problem is really that I can see all the columns. I will wait for more replies. Again thanks for your time!
  4. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I've not given up yet, still working on the sample provided with the flexible table class as its easier to follow but I think that it might be beyond my capabilities at the moment.
  5. RandomCoder

    RandomCoder Well-Known Member Licensed User

    It's late and time for bed, but I have managed to sort of get the sample flexible table class scrolling in a tabhost :). I say sort of because when scrolled to the bottom it does not fully display the last entry. I got it to work by setting the table panel size after adding the view. I also had terrible trouble getting it to show the table data after changing the dataset and found that by making the refreshTable subroutine public and calling this after loading the CSV data or the DB data it then worked flawlessly.
    This is the section of code that has enabled scrolling in the example (maybe I'm setting the view size too big and that's why the last rows are not shown... thinking out loud !)...
    "Table", pnlTable)
        pnlTable.Width = 
    Activity.Width        ' ### Needed to allow table to scroll!!!
        pnlTable.Height = Activity.Height    ' ### Needed to allow table to scroll!!!
    '    Activity.AddView(pnlTable, 20dip, 20dip, 100%x - 40dip, 100%y - 90dip) ' Original code line
    But unfortunately I'm still not able to get your sample working?

    Attached Files:

  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    @Peter Simpson what if you have more columns than you can practicaly show on the screen? I thought the table view supported horizontalscroll as well as verticalscroll?
    I've recently been playing with the design of my next app and in that I have placed a horizontalscrollview into a panel on the tabhost and then loaded a customlistview into it, this allows me to scroll in either direction and I should be able to format my rows better in that I could have multiple views per row. I'll probably have to limit the amount of rows though.
    Peter Simpson likes this.
  7. Peter Simpson

    Peter Simpson Expert Licensed User

    Yes you can so that 's 100% correct @RandomCoder :)
    I deliberately make sure that I never do that though as too many columns can be just confusing imo. Imagine if you had lets say 12 columns of just numbers. The numbers would make perfect sense until the table was scrolled horizontally then all hell would break lose (well not unless you have a good memory, unlike me ;)).

    No you are correct, but me I try very very very hard indeed to try to make sure that in any of my apps that horizontal scrolling just does not happen, but that's just me. If there is too much information, then I'll just find a way to redesign the screen until it all fits :cool:
    Last edited: Apr 11, 2015
    DonManfred and RandomCoder like this.
  8. RandomCoder

    RandomCoder Well-Known Member Licensed User

    And have you had to make the refresh table subroutine Public so that it can be called after updating the dataset? On my Nexus 7 using the sample supplied with the class I added the table panel to a tabhost and it would load correctly on startup but when switching datasets it just displayed a red background with the headers displayed and no data even though all the data was present in the data list. By calling refreshTable after loading the data the problem was fixed, but to do this I had to make the sub public.
    Peter Simpson likes this.
  9. Yafuhenk

    Yafuhenk Active Member Licensed User

    @Peter Simpson. Thanks for sharing some code. The issue I have is that I don't know upfront how many columns there are.
    I like to show the articles groups sold to a customer plus the totals, gross margin, planning and outlook. The number of article groups is not always the same as you can imagine. I therefore can't use the solution you gave.

    @RandomCoder. I am interested in your (partly) solution but I can't open the attachment. I still work with version 3.0. All I get is an empty file
    By the way I've set the panels on the tabhost to width and height of the activity and made the refreshtable sub public as suggest by you but that doesn't make any difference.

    Any other ideas?
    I really want to solve this.

    Thanks for you time

    Best regards

  10. RandomCoder

    RandomCoder Well-Known Member Licensed User

    OK @YAFUHENK please see if you can open the attached sample? This was created using B4A version 3.0 and is a copy of the original sample supplied with the Flexible Table Class. I've made 5 changes each commented with " ' ### Modified ### - Comment" so as to be easy to find. The first modification is that when adding the panel to the TabHost which is later to be used to hold the Flexible Table, you must set it's size otherwise I think that a panel with zero size gets added and then whilst the FlexibleTable is able to load into it, the effect is that it won't scroll. I could be wrong in my analysis of what's happening but the result is correct. Comment out the two lines and you will see that the table will not scroll again!
    The other 3 modifications are just to ensure that the data is displayed after being changed. I found that if I didn't refresh the table then I just ended up with a red background on my Nexus 7. Hopefully you can apply these same changes to your own project to get it working the way you require.

    PS. If you correctly set the size of the TablePanel then both the vertical and horizontal scrolls work and all data is displayed. In my previous post I was setting the panel too big and so unable to see the last few rows of the table :oops:

    Attached Files:

    Peter Simpson likes this.
  11. Yafuhenk

    Yafuhenk Active Member Licensed User

    Thanks @RandomCoder. Problem has been solved.
    The width and the height properties did the job indeed
    I added the last two lines in the code shown below.

    Table_customertbh.Initialize(Me, "Table_customertbh"10True)
        Table_customertbh.LoadSQLiteDB(SQLite, Query.Result(
    0), True)
        Table_customertbh.Width = customer_tbh.Width - 
        Table_customertbh.Height = customer_tbh.Height - customer_tbm.getTabHeight(customer_tbh) - Table_customertbh.RowHeight
    The only thing is that I can't see the status line which has been set to true but that's not the biggest issue.

    Thanks again !!

    RandomCoder likes this.
  12. klaus

    klaus Expert Licensed User

    I answer only today because I was on travel.

    You didn't see the the end of the columns nor the last rows because the Table was bigger than the internal TabHostPanel.
    You can calculate the width and height of the panel in a TabHost with the TabHostExtras library.
    Dim customer_tbh As TabHost
    Dim customer_tbm As TabHostExtras

    Dim rec1, rec2 As Rect
    rec1 = customer_tbm.getTabContentViewPadding(customer_tbh)
    rec2 = customer_tbm.getTabHostPadding(customer_tbh)
    Dim width, height As Int
    width = customer_tbh.width - rec1.Left - rec1.Right - rec2.Left - rec2.Right
    Dim TabHeight As Int
    TabHeight = customer_tbm.getTabHeight(customer_tbh)
    height = customer_tbh.Height - TabHeight - rec1.Top - rec1.Bottom - rec2.Top - rec2.Bottom
    00, width, height)
    There is another problem in your code, every time you click on a Tab you add a new Table.
    You must check if the doesn't Table exist to add a Table.

    Attached a modifyed version for the Table size.
    I did not check if the Table already exists nor the SQL problem.
    Don't be afraid for 'strange' colors, I added those for testing.
    I changed also a few dimensions to fit the layout to my device and see what happend.

    Attached Files:

    Yafuhenk and Peter Simpson like this.
  13. Yafuhenk

    Yafuhenk Active Member Licensed User

    Hi Klaus,
    I see that you responded to this topic as well.
    I recognized the problem in my code and I am very curious to see your improvements
    Unfortunetely I cant open the file because I am still using version 3.0.
    Do you have a possiblility to make the zip in 3.0?

    By the way does the statusline in the flexible table work in the tabview?
    I couldn't manage this so far.

  14. Yafuhenk

    Yafuhenk Active Member Licensed User


    I didn't read your reply very well. I did now
    Problem statusline solved !!

    Thank you very much for your time

    Best regards

    Last edited: Apr 14, 2015
  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