0

I am working on an Android application. I want to implement search functionality in my activity. I want that, when users press a button, a search dialog should appear and, after clicking, that search result should appear. Please help me.

2 Answers 2

1

The Android documentation has some quite good and extensive tutorials on implementing search functionality. You should take a look at:

http://developer.android.com/guide/topics/search/search-dialog.html

This will walk you through implementing search in your activity (Not you can skip the suggestions/ ContentProvider section)

To sum up the steps you need to take, you will declare your activity as searchable in your manifest.xml, state which activity will display the search results and implement the methods invoked when a search is made. Android can handle the search bar/input for you.

Sign up to request clarification or add additional context in comments.

Comments

0

Use AutoCompleteTextView for search.

public class AutoCompleteText extends Activity {

    String[] androidBooks = 
    {
        "Hello, Android - Ed Burnette",
        "Professional Android 2 App Dev - Reto Meier",
        "Unlocking Android - Frank Ableson",
        "Android App Development - Blake Meike",
        "Pro Android 2 - Dave MacLean",
        "Beginning Android 2 - Mark Murphy",
        "Android Programming Tutorials - Mark Murphy",
        "Android Wireless App Development - Lauren Darcey",
        "Pro Android Games - Vladimir Silva",
    };
    private String[] item = { "Aaaaa", "Bbbbb", "Ccccccc", "Dddddd", "Eeeeee", "Fccccc", "Gccc", "Haaa" };
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,item);
        AutoCompleteTextView acTextView = (AutoCompleteTextView)findViewById(R.id.AndroidBooks);
        acTextView.setThreshold(3);
        acTextView.setAdapter(adapter);


    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.