Android Question Programaticaly select Row on Table

Roger Daley

Well-Known Member
Licensed User
Longtime 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
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
wait... you wrote webview? why do you have the table in a webview?
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?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In Sub ReadDataBaseRowIDs replace this code
B4X:
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.
B4X:
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
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
In Sub ReadDataBaseRowIDs replace this code
B4X:
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.
B4X:
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


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
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
In Sub ReadDataBaseRowIDs replace this code
B4X:
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.
B4X:
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


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.

B4X:
'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
 
Upvote 0

klaus

Expert
Licensed User
Longtime 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.
 

Attachments

  • SQLiteLight2New.zip
    17.6 KB · Views: 158
Upvote 0
Top