I would like to use the value from an EditText
box to filter a ListView
.
Can you look at my coding and let me know what else I need to do to get it to work?
So far it only returns 0 rows.
Sub ButtonSearchFilterEventHandler_Click
' Populate the list.
'-------------------
DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
"FROM VisitResultTypes " & _
"WHERE ResultDescription = ? " & _
"ORDER BY ResultDescription", _
Array As String(EditTextResultDescription.Text), 0, _
ListViewResults, True)
End Sub
Additional Sub routines:
Sub Activity_Create(FirstTime As Boolean)
SQL.ExecNonQuery("CREATE TABLE VisitResultTypes " & _
"(Id INTEGER PRIMARY KEY, ResultDescription TEXT)")
End Sub
This one works. It shows all table rows:
Sub PopulateTheListView
' Populate the list.
'-------------------
DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
"FROM VisitResultTypes " & _
"ORDER BY ResultDescription", _
Null, 0, ListViewResults, True)
End Sub
I tried this but it returns all rows no matter what I type into the EditText box:
Sub ButtonSearchFilterEventHandler_Click
' Populate the list.
'-------------------
DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
"FROM VisitResultTypes " & _
"WHERE ResultDescription LIKE ? " & _
"ORDER BY ResultDescription", _
Array As String(EditTextResultDescription.Text & "%"), 0, _
ListViewResults, True)
End Sub
This one adds the data into the table:
SQL.ExecNonQuery2("INSERT INTO VisitResultTypes " & _
"(Id, ResultDescription) " & _
"VALUES " & _
"(?, ?)", Array As Object(Null, EditTextResultDescription.Text))
Update - Issue Solved:
I added another EditText box and used this to get the filtering to work:
DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
"FROM VisitResultTypes " & _
"WHERE ResultDescription LIKE " & "'" & EditTextSearchFilter.Text & "%' " & _
"ORDER BY ResultDescription", Null, 0, ListViewResults, True)