Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

How do you implement search functionality?

I went to the Android Developers site and I really couldn't follow their instructions. Do one of the later videos on the Android course show how to add this? Or can someone please tell me or lead me to a useful video to show me how to do this?

Ken Alger
Ken Alger
Treehouse Teacher

Michael;

Need additional information please. What are you trying to accomplish?

Ken

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Michael;

Sounds like an interesting project. It sounds like there are at least a couple of things to consider, first is how to practically do the search and two your search algorithm.

From a practical stand point you would need to:

  1. Create a search field (searchValue).
  2. Create a button to press for the search (`searchButton').
  3. Create an onClickListener for the searchButton and then pass the query with the searchValue onto your algorithm.

That part shouldn't be too large of a challenge.

Your algorithm though is where I think things would get more challenging unless you use one created elsewhere. As an example since you are doing math related topics, say my input for searchValue is "Finding the length of a side of a triangle if I know the other two sides." One would expect that I would be led to a Pythagorean Theory button. As such, your search algorithm would need to accommodate for that.

So, if you are asking for assistance in writing the code for the actual search field, button, and query that should be rather straight forward. If you are asking for assistance in writing the code for a custom search algorithm, that's an entirely different matter.

Ken

Are you trying to perform a web search or of your own app content? For a web search you can use the Intent constructor that takes an action String (constant from Intent class).

Intent searchIntent= new Intent(Intent.ACTION_WEB_SEARCH, Uri.parse("search with android"));

read the documentation for more info

Hey guys, sorry for the late response. What I have going on in my app is a set of buttons with math question on them, and I want to implement a search bar on the top where the user can start typing their questions and it will lead them to the button with the question on it.