Question

I am a newbie here and hope you can help me out to clear some of my understanding (or misunderstanding). I have been reading for days and trying out based on Android guide to implement search function but it really didn't work out well. Perhaps I've got the whole concept wrong so do help me out here if you can be kind.

I have an app which data is from remote xml and I want to implement search function. I have 1 main activity (under my SRC -> my package)that list all the data retrieved from the xml. My questions:

1) In the guide, it saws we must define a .Searchable Activity. I supposed this is to handle the search query and store the result? If this is a case, do I need to create a new activity or I can use my main activity as .Searchable Activity?

2) After the above item is done, I supposed I need to create an activity to receive the result and do something. I take it as I need to create "public class SearchableActivity extends ListActivity" in the activity I define in item 1? The problem is that I don't know what to do with this as the guide are incomplete.

3) Presumingly I did it successfully and upon search, there are some results return, how do I show (or filter to show the search result) in my main activity? I do not want to have another UI to show the result as I prefer it just get filter to show the matched records

4) Lastly, since my data is from remote xml, do I need to "search" based on remote xml or it will search based on cache info on the app?

I am sorry for being so ignorant but I am totally new here and hope you can help me out. So far I have no problem, getting the dialog shown on my action bar. The only problem is that the search didn't work at all :( upon search, there is just nothing happened.

Thanks very much in advance. Cheers!

Was it helpful?

Solution

For searching in a list you can use built-in functions of android, but if you want a good result you can use your own function. The simplest function is:

for(int i = 0 ; i < arraylisy.size() ; i++)
{
    if(arraylist.get(i) == youobject)
        return true;
}
return false;

but there are better functions like binary search that you can use. Now, how to create search activity?

First: create XML file an add a listview in it.
Second: create java file and link xml file to it.
Now use above code to search an object on your list. If in every search you find several items then add them to new listview.

Now create an adapter and send your search list to that.
Finally set your adapter to listview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top