B4i Library [class] SearchView

John Woodsmall

Active Member
Licensed User
Longtime User
"New" from:"narek-adonts"
sv_ItemClick(Value As String) not returning a value when
B4X:
Dim states As List = File.ReadList(File.DirAssets, Temp_TextField.text & ".TXT")
        sv.SetItems(states)

any ideas on this?
 

Haris Hafeez

Active Member
Licensed User
Longtime User
Just looked at this class. While I haven't spent much time on going through the actual code, I can see that click values are not being returned. This is because a TextField called 'et' is used (I'm not sure why). If you just want to have the value that is clicked upon returned to you in the callback, just replace et.text with cell.text.ToString in the following two methods:
tblSearchResult_SelectedChanged and lv_SelectedChanged

To the original author, please let us know if this is going to break something. So far it looks fine but I've only just ran the example.
 

Haris Hafeez

Active Member
Licensed User
Longtime User
SearchView raises the ItemClick event. You don't need to modify the code.
The question is about the value being passed to this callback. In my test and the one reported by John, the valued passed back is blank for which I had to modify the code.
 

tufanv

Expert
Licensed User
Longtime User

Dear Narek,

In this implmentation is it possible to change th listview is visible only after something is searched ? Altough the lv.visible is false the list of results are always visible without writing anything to search box ?
Also another question : ıs it possile to change the hinttext of searchbox. It is "search" at the moment and i want to change it to another language .
TY
 

narek adonts

Well-Known Member
Licensed User
Longtime User
Will post a fixed version today
 

narek adonts

Well-Known Member
Licensed User
Longtime User
Didnt understood the first question
 

tufanv

Expert
Licensed User
Longtime User
Didnt understood the first question

What i mean is , there will be only a searchbox (the textfield ) and with some words written , the results will be seen. ın this example the results are visible from the begining .
 

narek adonts

Well-Known Member
Licensed User
Longtime User
What i mean is , there will be only a searchbox (the textfield ) and with some words written , the results will be seen. ın this example the results are visible from the begining .

It is a regular page. You can do whatever you want. hide, show, add views,...
 

tufanv

Expert
Licensed User
Longtime User
It is a regular page. You can do whatever you want. hide, show, add views,...
In the code module i tried lv.visible=false to make only et visible not the results but that hided also the textview.
The list of cities is visible before typing anything to searchbox. Can you tell how can i hide the results when noting is typed ,
 

narek adonts

Well-Known Member
Licensed User
Longtime User
In the code module i tried lv.visible=false to make only et visible not the results but that hided also the textview.
The list of cities is visible before typing anything to searchbox. Can you tell how can i hide the results when noting is typed ,
try lv.clear
 

narek adonts

Well-Known Member
Licensed User
Longtime User
In the code module i tried lv.visible=false to make only et visible not the results but that hided also the textview.
The list of cities is visible before typing anything to searchbox. Can you tell how can i hide the results when noting is typed ,


There are 2 options.

1. Add the search Textview to the page root panel and not to the tableview
2. Add a view over the table view
 

narek adonts

Well-Known Member
Licensed User
Longtime User
Please see attached the fixed version.

It fixes the bug with Click Event and also and change the return type to TableCell instead of String.
 

Attachments

  • searchView.zip
    4.4 KB · Views: 60

Alvsky

Member
Licensed User
Longtime User
Hi all
Is there a way to change the background color of listed items.
I tried to set lv.Color in SearchView to some color but list background still remained white?!?
I use Erel's version of SearchView

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to create a custom view for each item:
B4X:
Private Sub AddItemsToList(li As List, full As String)
   If li.IsInitialized = False Then Return
   Dim rs As RichString
   rs.Initialize("")
   For i = 0 To li.Size - 1
     Dim item As String
     item = li.Get(i)
     item = item.ToLowerCase
     If full.Length > MAX_LIMIT And item.Contains(full) = False Then
       Continue
     End If
     rs.Text = li.Get(i)
     If full.Length > 0 Then
       Dim ii As Int = item.IndexOf(full)
       rs.Color(Colors.Red, ii, ii + full.Length)
     End If
     Dim tc As TableCell = lv.AddSingleLine("")
     Dim p As Panel
     p.Initialize("")
     p.Color = Colors.Blue
     p.SetLayoutAnimated(0, 1, 0, 0, lv.Width, lv.RowHeight)
     Dim lbl As Label
     lbl.Initialize("")
     rs.SetToLabel(lbl)
     p.AddView(lbl, 5, 2, lv.Width, lv.RowHeight)
     tc.CustomView = p
     
   Next
   lv.ReloadAll
End Sub
Make sure to set lv.RowHeight = 30 in the Initialize sub.
 

Alvsky

Member
Licensed User
Longtime User
Thanks for the solution. It colors cells now but it has a bug. When I click on the item Value is empty.
It looks like ItemClick works only if tc.Text is set.
To make it work, I added tc.Text = rs.AttributedString and made lbl not Visible but I am not sure is that a right way to do it



B4X:
Private Sub AddItemsToList(li As List, full As String)
   If li.IsInitialized = False Then Return
   Dim rs As RichString
   rs.Initialize("")
   For i = 0 To li.Size - 1
     Dim item As String
     item = li.Get(i)
     item = item.ToLowerCase
     If full.Length > MAX_LIMIT And item.Contains(full) = False Then
       Continue
     End If
     rs.Text = li.Get(i)
     If full.Length > 0 Then
       Dim ii As Int = item.IndexOf(full)
       rs.Color(Colors.Red, ii, ii + full.Length)
     End If
     Dim tc As TableCell = lv.AddSingleLine("")
tc.Text = rs.AttributedString
     Dim p As Panel
     p.Initialize("")
     p.Color = Colors.Blue
     p.SetLayoutAnimated(0, 1, 0, 0, lv.Width, lv.RowHeight)
     Dim lbl As Label
     lbl.Initialize("")
lbl.Visible = False 
     rs.SetToLabel(lbl)
     p.AddView(lbl, 5, 2, lv.Width, lv.RowHeight)
     tc.CustomView = p
   Next
   lv.ReloadAll
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…