Android Question using b4xtable to view send and recieved sms

Discussion in 'Android Questions' started by Makumbi, Apr 12, 2019.

  1. Makumbi

    Makumbi Active Member Licensed User

    Please members i have two tables sentmessages and recivedmessages but iam failing to view the list of of information returned from diferent especially the one for sentmessages when i click on sent for the first time it doesnot show any record but on the second time it shows the table with more columns please how can i implement this modify my code from this attachment to help you get what i wanted please help me iam failing out on this yet i wanted to implement this using B4xtable please help
     

    Attached Files:

  2. DonManfred

    DonManfred Expert Licensed User

  3. Makumbi

    Makumbi Active Member Licensed User

    Please DonManfred show me that very code from my attachment because yesterday i tried Erels answer here! https://www.b4x.com/android/forum/threads/b4xtable-shows-duplicated-columns.104761/#post-656339 but the problem still can not be solved please highlight for me that very code that is creating problems . i have spent sleepless nights on this thing please help
     
  4. mangojack

    mangojack Well-Known Member Licensed User

    I have tried to get your sample project working with no luck. (no data displayed in Table full stop)

    There is Data being received from http jobs but it is not getting placed /stored in the database tables for final display in your Table.

    It would appear all this current problem / threads is due to the fact you wish your 1st Column Title to have a different Title depending on the data displayed.

    Just load your Table Columns Once only in Activity_Create ... (Not in any other Sub) and give the 1st column a title of "Date" (Problem Solved for the time being)

    I thought you should be able to change the column title when necessary with ...
    Code:
    Private DateColumn As B4XTableColumn 'Global

    Sub Activity_Create(FirstTime As Boolean)
          
        DateColumn = B4XTable1.AddColumn(
    "Date", B4XTable1.COLUMN_TYPE_TEXT) 
      
             
        
    'then somewhere later ....  
        DateColumn.Title = "Date Recieved"
    but it is not working and I will follow it up ...;)


    If you need any further help (regarding records not displaying)you really need to upload the most Basic, Stripped Down sample ...
    That has just enough code to achieve what you are trying to do , but failing. (by doing that you will most likely solve the problem yourself. :))

    ps: I have a test projects where each new element or task is tested and researched .. only when it is running 100% (well 95%) , do i incorporate it into the main project.
    Get the b4xTable example back out and load it with a small amount of dummy data ... in a way that mirrors your project. Keep it very simple.
    When you have got it working the way you wish you will have template code for you project.

    ps2: you do not need to call DateTime.Format before each DateTime interaction / display code block.
    Once you have set the format it is as is until you reset / change the format again.
     
    jimmyF likes this.
  5. mangojack

    mangojack Well-Known Member Licensed User

    As a follow up ... (to solve one of your problems )

    1. Declare a B4XTableColumn object in Globals ..
    2. Set your Table columns in Activity_Create (or somewhere else , But only Once)
    3. Edit / change the column title when neccessary


    Code:
    Private DateColumn As B4XTableColumn   'Global declaration.

    Sub Activity_Create(FirstTime As Boolean)
        DateColumn = B4XTable1.AddColumn(
    "Date", B4XTable1.COLUMN_TYPE_TEXT)   
        B4XTable1.AddColumn(
    "Sms", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "ID", B4XTable1.COLUMN_TYPE_TEXT)
        
    '.....................


    Sub ShowTable             'Again .. You should rename this to something like ... DisplaySentSMS
        '...........................    
        B4XTable1.SetData(data)
        
    Dim pnl As B4XView = DateColumn.CellsLayouts.Get(0'header panel
        pnl.GetView(0).Text = "Date Sent"


    Sub ShowTable2            'how about .. DisplayReceivedSMS
        '...........................   
        B4XTable1.SetData(data)
        
    Dim pnl As B4XView = DateColumn.CellsLayouts.Get(0'header panel
        pnl.GetView(0).Text = "Date Received"
    Best of luck ...
     
  6. Makumbi

    Makumbi Active Member Licensed User


    thanks for the support where do i place this code
    Code:
    Dim rs As ResultSet = Starter.SQL1.ExecQuery("SELECT DISTINCT Datesent,Sms as SentMessage,ID FROM Sentmessages")
        
    Do While rs.NextRow
            
    Dim row(4As Object
            row(
    0) = rs.Getstring("Datesent")
            row(
    1) = rs.GetString("SentMessage")
            
            
    'Log(row(0))
            'Log(row(1))
            'Log(row(2))
            '& " " & rs.GetString("LastName")
            row(2) = rs.GetString("ID")
            
    'Some of the fields are Null. We need to convert them to empty strings:
            If row(2) = Null Then row(2) = ""
            row(
    1) = rs.GetString("SentMessage")
            data.Add(row)
        
    Loop
        rs.Close
     
  7. mangojack

    mangojack Well-Known Member Licensed User

    Exactly where it is presently. The Sub code I posted above has just been trimmed to show what was necessary.
     
  8. Makumbi

    Makumbi Active Member Licensed User

    I Have tried it this way but the code gives me this error
    Code:
    Dim pnl As B4XView = DateColumn.CellsLayouts.Get(0'header panel
        pnl.GetView(0).Text = "Date Sent"
        data.Initialize
        
    Dim rs As ResultSet = Starter.SQL1.ExecQuery("SELECT DISTINCT Datesent,Sms as SentMessage,ID FROM Sentmessages")
        
    Do While rs.NextRow
            
    Dim row(4As Object
            row(
    0) = rs.Getstring("Datesent")
            row(
    1) = rs.GetString("SentMessage")
            
            
    'Log(row(0))
            'Log(row(1))
            'Log(row(2))
            '& " " & rs.GetString("LastName")
            row(2) = rs.GetString("ID")
            
    'Some of the fields are Null. We need to convert them to empty strings:
            If row(2) = Null Then row(2) = ""
            row(
    1) = rs.GetString("SentMessage")
            data.Add(row)
        
    Loop
        rs.Close
        B4XTable1.SetData(data)
    here is the error i get
    Code:
    Error occurred on line: 601 (B4XTable)
    android.database.sqlite.SQLiteException: near 
    ")": syntax error (code 1): , while compiling: CREATE TABLE data )
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:
    889)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:
    500)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:
    588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:
    58)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:
    31)
        at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:
    1677)
        at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:
    1608)
        at anywheresoftware.b4a.sql.SQL.ExecNonQuery(
    SQL.java:74)
        at b4a.example.b4xtable._createtable(b4xtable.java:
    1979)
        at b4a.example.b4xtable$ResumableSub_SetData.resume(b4xtable.java:
    406)
        at b4a.example.b4xtable._setdata(b4xtable.java:
    345)
        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:351)
        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.raiseEvent2(BA.java:
    180)
        at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:
    262)
        at b4a.example.main._showtable(main.java:
    1394)
        at b4a.example.main._btnedit_click(main.java:
    1383)
        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:351)
        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.raiseEvent2(BA.java:
    180)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    176)
        at anywheresoftware.b4a.objects.ViewWrapper$
    1.onClick(ViewWrapper.java:80)
        at android.view.View.performClick(
    View.java:5610)
        at android.view.View$PerformClick.run(
    View.java:22265)
        at android.os.Handler.handleCallback(Handler.java:
    751)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    154)
        at android.app.ActivityThread.main(ActivityThread.java:
    6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    756)
     
  9. DonManfred

    DonManfred Expert Licensed User

    your code does not match the error.
     
  10. Makumbi

    Makumbi Active Member Licensed User

    The code runs but when it reaches at
    Code:
    B4XTable1.SetData(data)
    i get
    Code:
    Error occurred on line: 601 (B4XTable)
    android.database.sqlite.SQLiteException: near 
    ")": syntax error (code 1): , while compiling: CREATE TABLE data )
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:
    889)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:
    500)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:
    588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:
    58)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:
    31)
        at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:
    1677)
        at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:
    1608)
        at anywheresoftware.b4a.sql.SQL.ExecNonQuery(
    SQL.java:74)
        at b4a.example.b4xtable._createtable(b4xtable.java:
    1979)
        at b4a.example.b4xtable$ResumableSub_SetData.resume(b4xtable.java:
    406)
        at b4a.example.b4xtable._setdata(b4xtable.java:
    345)
        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:351)
        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.raiseEvent2(BA.java:
    180)
        at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:
    262)
        at b4a.example.main._showtable(main.java:
    1394)
        at b4a.example.main._btnedit_click(main.java:
    1383)
        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:351)
        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.raiseEvent2(BA.java:
    180)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    176)
        at anywheresoftware.b4a.objects.ViewWrapper$
    1.onClick(ViewWrapper.java:80)
        at android.view.View.performClick(
    View.java:5610)
        at android.view.View$PerformClick.run(
    View.java:22265)
        at android.os.Handler.handleCallback(Handler.java:
    751)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    154)
        at android.app.ActivityThread.main(ActivityThread.java:
    6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    756)
     
  11. Makumbi

    Makumbi Active Member Licensed User

    Code:
    Sub Activity_Create(FirstTime As Boolean)

        
    If FirstTime Then
            smiley = LoadBitmapResize(
    File.DirAssets, "smiley.png"24dip24dipFalse)
        
    End If
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'If  IsConnectedToInternet=True Then
            replysms
            
    'HighPriority_Notification
            Activity.LoadLayout("simplechat")
        
    Activity.Title="Chat"
        DateColumn = B4XTable1.AddColumn(
    "Date", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "Sms", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "ID", B4XTable1.COLUMN_TYPE_TEXT)
    Code:
    Sub ShowTable
        
        
    Dim pnl As B4XView = DateColumn.CellsLayouts.Get(0'header panel
        pnl.GetView(0).Text = "Date Sent"
        
        
    End Sub


    Sub ShowTable2

        
        
    Dim pnl As B4XView = DateColumn.CellsLayouts.Get(0'header panel
        pnl.GetView(0).Text = "Date Received"


        
    'B4XTable1.SetData(data)
    End Sub
    the codes above show how i have done it now the problem is showing data from the respective tables
    Now which code can i use to show data from sent message and the data from received messages
     
  12. mangojack

    mangojack Well-Known Member Licensed User

    Seeing this thread @Erel is probably having a fit....


    @Makumbi .. you are not reading well / understanding the replies (maybe a language thing ??)

    The uploaded sample project is an exact duplicate of what you uploaded in post#1.

    The only changes have been the inclusions of suggested code in post #5 to change Column Title during Runtime.

    1. It does not solve other problems you are having ... (data does not show in the Table - All data! ... not just some)
    (I have attempted but do not understand / follow your code)

    2. try to Log / Study why it does not Display (The data seems to be arriving from http jobs OK)

    Once you have decided which problem you which to solve first .. upload a small project so we might understand the issue better.

    Maybe time for a fresh thread ..:confused:
     

    Attached Files:

  13. Makumbi

    Makumbi Active Member Licensed User

    Thanks mangojack but the problem is when i click on the sent message i dont see the data returned that is one of my biggest concern i was trying to explain to Erel it is good that you have also seen it . but how comes that when you look at the record counter it shows you 1 out of 4 show which shows that data is already there and wen i look at my log i can see the messages and the dates properly
    Code:
    11/04/2019 03:16 PM
    good morning
    java.lang.Object@5b276d5
    12/04/2019 07:57 AM
    good works
    java.lang.Object@aefaeea
    12/04/2019 03:48 PM
    good boy
    java.lang.Object@254f5db
    12/04/2019 04:03 PM
    BBC DJ
    's
    java.lang.Object@3779878
     
  14. mangojack

    mangojack Well-Known Member Licensed User

    So use many logs ... at many stages ... to show where it is Breaking !


    The only way I / We can help ...

    1 Start a New Thread , ie: Received Data not showing in Table"

    2 Upload a sample project that only contains code to ...
    a. display your layout / table
    a. get you data via http job ... (Only that Data / Job / Json)
    b. process the Json string
    c. display the processed data in b4xTable

    No More ... No Less

    As I stated earlier ... do that and you will probably solve the problem yourself.;)
     
  15. mangojack

    mangojack Well-Known Member Licensed User

    I had a fresh look at your sample project in an attempt to understand it more and possibly helping with your problem.
    Unfortunately I am still stumped exactly what your trying to achieve (apart from getting some data and displaying in Table.)

    I have made some changes to the sample to try and simplify it ... ie. the assets db file now contains all Tables and base info.
    I have made comments to explain.
    Also I changed some button names to make it clearer what they do in the example.

    You will see comments highlighting areas not working .. (I just gave up in the end :confused:)


    Probably your first stop might be ReplySMS Sub .. There is no data coming in from your http job

    Possibly fix that first .

    Also it might help if you added many comments explaining what you are doing / trying to do.
    ie: what is the purpose of http job in Activity_Create.

    It might help with future problems.
     

    Attached Files:

    Last edited: Apr 13, 2019
    DonManfred likes this.
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