1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Programaticaly select Row on Table

Discussion in 'Android Questions' started by Roger Daley, Jun 12, 2019.

  1. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hi All,

    I have SQL db/list/webview I am trying to have the Webview/table "Select" a the Row of a newly added record. The following pictures from a modified SQL2 example may explain this better:

    Screen1.jpg
    Screen1 shows 4 records the second line selected.

    Screen2.jpg
    Screen2 shows a newly added record. By default the first line is selected. I want the latest record to be selected.
    IE

    SCreen3.jpg

    I have worked out a way to do this but it is messy and convoluted. Before I code a complete mess my question is:

    Is there a function/option to go to the new record as if the WebView has been clicked?
    This is a bit odd as it is arse about to the normal operation. I think I am searching for something that does not exist, but worth asking.

    Thanks in advance
     
  2. sorex

    sorex Expert Licensed User

    ain't it just

    Code:
    mytable.SelectedRow=mytable.Items.Size 'maybe -1
    ?
     
  3. sorex

    sorex Expert Licensed User

    wait... you wrote webview? why do you have the table in a webview?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The html table doesn't show any selection. It just uses a different color for the titles.

    I recommend you to switch to B4XTable. It is much more powerful.
     
  5. Roger Daley

    Roger Daley Well-Known Member Licensed User

    I should have said the screen shots I've shown are from Klaus' SQL2 Example program modified to automatically sort the entries.
    This example has a table in a webview. 2.6.1.3 B4X Booklet SQLite Database. Is there an issue?
     
  6. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks for the reply Erel but I don't need anything more powerful than this. This last bit is a "nice to have" but not essential.
     
  7. klaus

    klaus Expert Licensed User

    In Sub ReadDataBaseRowIDs replace this code
    Code:
    If RowIDList.Size > 0 Then
        CurrentIndex = 
    0                            'set the current index to 0
    Else
        CurrentIndex = -
    1                            'set the current index to -1, no selected item
        ToastMessageShow("No items found"False)
    End If
    ResultSet1.Close                                                
    'close the ResultSet, we don't need it anymore
    by this one.
    Code:
    If RowIDList.Size > 0 Then
        
    If CurrentIndex = -1 Or CurrentIndex > RowIDList.Size - 1 Then
            CurrentIndex = 
    0                            'set the current index to 0
        End If
    Else
        CurrentIndex = -
    1                            'set the current index to -1, no selected item
        ToastMessageShow("No items found"False)
    End If
    ResultSet1.Close                                                
    'close the ResultSet, we don't need it anymore
     
    AnandGupta likes this.
  8. Roger Daley

    Roger Daley Well-Known Member Licensed User


    Thanks Klaus,
    I'm away from the computer at the moment so will be a while before I get back.
    Just looking at it is encouraging.

    Regards Roger
     
    AnandGupta likes this.
  9. AnandGupta

    AnandGupta Active Member Licensed User

    *LIKE*

    Regards,

    Anand
     
  10. Roger Daley

    Roger Daley Well-Known Member Licensed User


    Klaus,

    Unfortunately not quite right. The two attached screen shots Before and After of adding record 3.

    Before.jpg After.jpg

    I guess what this shows is that I need a way to set the currentindex to match the highest RowID.
    That I have added an "Order By" to the SUB makes it a bit more complex.

    Code:
    'Reads the database rowids in RowIDList
    Private Sub ReadDataBaseRowIDs
        
    Private ResultSet1 As ResultSet
        
        
    If Filter.flagFilterActive = False Then
            ResultSet1 = SQL1.ExecQuery(
    "SELECT rowid FROM persons ORDER BY UPPER(LastName) ASC")
        
    Else
            ResultSet1 = SQL1.ExecQuery(
    "SELECT rowid FROM persons"  & Filter.Query)
        
    End If
        
        
    'We read only the rowid column and put them in the IDList
        RowIDList.Initialize                                'initialize the ID list
        Do While ResultSet1.NextRow
            RowIDList.Add(ResultSet1.GetInt2(
    0))        'add the rowid's to the RowID list
        Loop
        
    If RowIDList.Size > 0 Then
            
    'CurrentIndex = 0                            'set the current index to 0
            If CurrentIndex = -1 Or CurrentIndex > RowIDList.Size - 1 Then
                CurrentIndex = 
    0                            'set the current index to 0
            End If

        
    Else
            CurrentIndex = -
    1                            'set the current index to -1, no selected item
            ToastMessageShow("No items found"False)
        
    End If
        ResultSet1.Close                                                
    'close the ResultSet, we don't need it anymore
    End Sub
    Regards Roger
     
  11. klaus

    klaus Expert Licensed User

    I tested it with my SQLiteLight2 program and it worked.
    You hadn't said in your first post that your list is sorted.

    Try the attached project. It works with the rowIDs.
     

    Attached Files:

  12. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Brilliant Klaus,

    Sorry about missing to tell you it was sorted, in my mind I had but the only clue was the screen shots. A bit vague.

    All working well and looks simpler than what I was trying to do.

    Regards Roger.
     
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