- Home /
How Do I display Search results using Input Fields?
Hey how's it going guys.
So I'm having a bit of an issue trying to display a list of results as GUI Buttons inside the content of a Scroll View object. I want to be able to type into a Input field at the top "Appl" and have all the buttons with those characters to be displayed from top to bottom in alphabetical order inside the Scroll View. Kind of like:
And then once you enter in any text it finds the results and displays the buttons at the top and gets rid of the other buttons. Kinda like:
It would really be appreciated even if you could tell me the direction I would need to go, Thanks guys!
Answer by phxvyper · Apr 02, 2016 at 09:54 PM
Keep a List of all of the buttons that are options. Every time the text in the InputField changes, loop through each button and compare the values of the text of the button and the text in the InputField.
List<Button> Buttons = new List<Button>();
//On input field text changed:
if (input.IsEmptyOrNull())
{
foreach (Button b in Buttons)
{
//Unhide every button
}
}
else
{
foreach (Button b in Buttons)
{
if (!b.text.Contains(input))
{
//hide buttons that don't contain the input.
}
}
}
Answer by farukaf · Nov 25, 2016 at 07:57 AM
Look the inspector you will have "On Value Changed (String)" So you just have to make a event to be called when u type things up.
So make a script. Put all buttons there. Set then on editor.
And make something like this (not "real" code):
public void HideButtons (string field)
{
//make your filter here
}
then call it at the "On Value Changed (String)" on editor. Hope you get it..
Your answer
Follow this Question
Related Questions
How to make Input.GetAxis work on certain area only? 0 Answers
UnityEngine.UI.dll 0 Answers
LoadLevelAsync multiple pending scenes? 0 Answers
Detect if UI Image is in a trigger 1 Answer
How to shrink text size 1 Answer