How can I pass the ID of each entry to SearchView? The records is not unique.
It is required to return the value "i" of each selected entry by SearchView1_ItemClick.You need to provide some more information and some sample code for anyone to understand what your question is.
Private m As Map
m.Initialize
Dim lst As List
lst.Initialize
For i=0 To 5
m.Put(i,"name")
Next
For i=0 To m.Size-1
lst.Add(m.GetValueAt(i))
Next
index = SearchView1.SetItems(lst)
'Alter SearchView to return the index instead of the value
Private Sub lv_ItemClick (Position As Int, Value As Object)
et.Text = Value
et.SelectionStart = et.Text.Length
ime.HideKeyboard
lv.Visible = False
If SubExists(mCallback, mEventName & "_ItemClick") Then
CallSub2(mCallback, mEventName & "_ItemClick", Index)
End If
End Sub
Sub SearchView1_ItemClick(index as int)
MsgboxAsync("Chosen index: " & Index&CRLF&"Chosen value is "&m.get(i), "")
End Sub
Please look at the attached example. I can't do anything.Then you can use the map you created.
This complete example uses B4XSearchTemplate (requires Xui Views lib checked). If you want to use it instead of the old SearchView:Please look at the attached example. I can't do anything.
Sub Globals
Private Dialog As B4XDialog
Private XUI As XUI
Private SearchTemplate As B4XSearchTemplate 'need XUI VIEWS lib
End Sub
Sub Activity_Create(FirstTime As Boolean) 'ignore
Dialog.Initialize (Activity) 'you can use B4XPages too
SearchTemplate.Initialize
Private m As Map
m.Initialize
Dim lst As List
lst.Initialize
For i=0 To 5
m.Put(i,"name" &i)
Next
For Each k As Int In m.Keys
lst.Add(k)
Log($"${k} ${m.Get(k)}"$)
Next
SearchTemplate.SetItems(lst)
Wait For (Dialog.ShowTemplate(SearchTemplate, "", "", "CANCEL")) Complete (Result As Int)
If Result = XUI.DialogResponse_Positive Then
Log(SearchTemplate.SelectedItem)
End If
End Sub
Pay attention to the warnings in your log.Please look at the attached example. I can't do anything.
Main - 47: Parameter name cannot hide global variable name.
The recommended value for android:targetSdkVersion is 33 (manifest editor). (warning #31)
Log(m.get(m.get(index)))
Sub SearchView1_ItemClick(i As Int)
Log(m.get(i))
End Sub
I'm not on my development machine, but...I have attached the original SearchView example, in which I am trying to return the sequence number in the cities list.
Please look at the code and, if possible, suggest the correct solution.
Private Sub lv_ItemClick (Position As Int, Value As Object)
et.Text = Value
et.SelectionStart = et.Text.Length
ime.HideKeyboard
lv.Visible = False
If SubExists(mCallback, mEventName & "_ItemClick") Then
' Don't return the value CallSub2(mCallback, mEventName & "_ItemClick", Value)
' Return the index
CallSub2(mCallback, mEventName & "_ItemClick", Position)
End If
End Sub
Sub SearchView1_ItemClick(Position as int)
Log("Chosen index: " & Position)
End Sub
Sub SearchView1_ItemClick(Position as int)
Log("Chosen index: " & Position)
log($Chosen city is: ${cities.get(Position)}")
End Sub
I'm already at a loss as to how to do this. And I don't understand anything anymore.You don't need all of that Cities stuff in the SearchView
Keep the cities in a global variable in Main
Please, when you have the opportunity, correct my code.I'm not on my development machine, but...
Made. What is returned is not the city index that was from the list of cities, but the index from the search results.I have corrected your code. You just need to copy it in.
It works if all items in the list are unique, but if for instance you have Moscow the one in Russia and another Moscow in America, one of them is bumped up unless you make one start with a lower case and the other with upper case.My head became clearer in the morning
Thank you, I understand that. But I didn't find any other solutionIt works if all items in the list are unique
There is another solution if you are interested: If it is a concern to you, and you have 2 items the same, you can capitalize the first letter of one and lower case the first letter of the other. This way you have no duplicates for your map. If you need help with it, come backI understand that. But I didn't find any other solution