Android Question Flexible Table

Discussion in 'Android Questions' started by Domingo Garcia, Jan 19, 2018.

  1. Domingo Garcia

    Domingo Garcia Member Licensed User

    Hello, I've been learning the B4A for a couple of weeks and find it a very useful tool. I downloaded the TableV2.22 and used it to display a table in a data form with a SQLite3DB Table of transactions to fill the table in the lower half of the screen. I would like to see an example of double click on a cell and update the cell value and from the new value update the SQLite table. does anybody have an example like that. would I need a separate update button after the data is changed?

    Great job with B4A (purchased it 5 days ago)
    What is the latest version of the Table Class?
     
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Why double click, Android is not Windows???
    You should be using the _LongClick.

    Enjoy...
     
    Last edited: Jan 19, 2018
    mangojack likes this.
  3. Domingo Garcia

    Domingo Garcia Member Licensed User

    ok, how about the rest, is there a sample of a long click that let's you change the value of a cell and update the database.
     
  4. klaus

    klaus Expert Licensed User

    Sorry, but I am leaving now for the whole day.
    Will have a look at it tomorrow.
     
  5. klaus

    klaus Expert Licensed User

    There is no update method included in the library, you need to do it on your own.
    You can use CellClick and CellLongClick events for the celles in the Table like this:
    Code:
    Sub Table1_CellClick(col As Int, row As Int)
        
    Log("row = " & row & "  col = " & col)
    End Sub

    Sub Table1_CellLongClick(col As Int, row As Int)
        
    Log("row = " & row & "  col = " & col)
    End Sub
    You could have a look at the B4A User's Guide (link in my signature), it includes a chapter about SQLite databases with examples.
    These examples include an Edit method for whole entries not just for one cell, they don't use the Table class but a WebView, but the principle is the same.
    You can find these examples also HERE.
     
  6. Domingo Garcia

    Domingo Garcia Member Licensed User

    Hello,
    I'm trying to fill a table with data from an SQLite database but in my case I have two databases opened. one SQL1 and the other SQL2 but when I call the LoadSQLiteDB2 with command:
    Table1.LoadSQLiteDB2(SQL2, stmt, True, Array As String("T", "T", "I", "I", "T"))
    I get the error: android.database.sqlite.SQLiteException: no such table: checkout (code 1): , while compiling: SELECT Product, Description, Tipo, Qty, Status FROM checkout WHERE Route = '15A' AND Trndate = '20180126'.
    This used to work when I had only one database opened.
     
  7. klaus

    klaus Expert Licensed User

    Where do you initialize SQL2? Mybe you need a module prefix if it is initialized in another module.
    Are you sure that the Table name in stmt is correct ?
     
  8. Domingo Garcia

    Domingo Garcia Member Licensed User

    SQL2 is initialized in the "Checkout" module that calls the Table class and the table name is correct. This used to work until i separated this table to a second database. Is there an issue with having two databases opened at the same time. I open the first in the Main module and the second is the Checkout module where both are used, in the Activity_Create sub.
    If SQL2.IsInitialized = False Then
    SQL2.Initialize(File.DirInternal, TRFName, True)
    End If
     
  9. klaus

    klaus Expert Licensed User

    Can you post a small example showing the problem or post your project as a zip file?
    Without seeing the code it's impossible to give a concrete advice.
     
  10. Domingo Garcia

    Domingo Garcia Member Licensed User

    Where is the database file supposed to be placed. I made changes to the tables but it seems to be picking up and old version. I placed the db in the Files folder of the project and I get the message "File 'panwh.db' is not used (warning #15). When i print to log the dbpath it shows: /data/user/0/b4a.example/files...but I can't find that path anywhere. Do I need to run any command to have it pick up the new db file. I haverecompile various times and still get an error.
    android.database.sqlite.SQLiteException: no such column: FlgCheck (code 1): , while compiling: SELECT UserID, UserName, UserLevel, PwEncrypt, PwKey, Status, FlgCheck, FlgLoad, FlgMorn, FlgInvt FROM Users Where UserId = ?
    there was a spelling error on the column name which I fixed but it's not picking up the change.

    #Region Project Attributes
    #ApplicationLabel: Checkout
    #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 SQL1 As SQL
    Public DBPath = File.DirInternal As String
    Public DBFName As String = "panwh.db"

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Log(DBPath)
    If SQL1.IsInitialized = False Then
    SQL1.Initialize(DBPath, DBFName, True)
    End If
    Activity.LoadLayout("login")
    CheckWiFi
    End Sub

    Sub Validate_Login (uid As String, psw As String) As Boolean

    Dim Cursor1 As Cursor
    Dim stmt As String
    Dim pwe As String
    Dim rc = False As Boolean
    status = ""
    stmt = "SELECT UserID, UserName, UserLevel, PwEncrypt, PwKey, Status," _
    & " FlgCheck, FlgLoad, FlgMorn, FlgInvt FROM Users Where UserId = ?"
    Cursor1 = SQL1.ExecQuery2(stmt, Array As String(uid)) ' Here is where it cancels
    Cursor1.Position = 0
    status = Cursor1.GetString("Status")
    If status = "1" Then
    check = Cursor1.GetString("FlgCheck")
     
  11. Mahares

    Mahares Well Known Member Licensed User

    You must copy the database file programatically from the Assets folder to the internal folder like this, before you can use it and open it.
    Code:
    If File.Exists(File.DirInternal,"panwh.db") =False Then   'you can use your variable name for the file name
            File.Copy(File.DirAssets,"panwh.db",File.DirInternal,"panwh.db")
    End If
    Please use code tags when you post code. It is easier to decipher it, Domingo.
     
  12. Domingo Garcia

    Domingo Garcia Member Licensed User

    Ok I'll try that.
    How can I then test to see if the file in the assets folder is newer then the one in the DirInternal to replace it.
     
  13. Domingo Garcia

    Domingo Garcia Member Licensed User

    MR. Mahares, that was it! Now every thing is working. Muchas Gracis. I found LastModified method but it said it doesn't support files in the assets directory.
     
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