0

i tried to put a searchbar into my app and i got it so far to type in what i wanna search, but how do i "send" that given information? The problem is i can type something in, but theres no button to start the search and i dont have much experience in app building...

the menu:

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.klassenliste, menu);
    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
     SearchView searchView =
             (SearchView) menu.findItem(R.id.search).getActionView();
     searchView.setSearchableInfo(
             searchManager.getSearchableInfo(getComponentName()));

    return true;
}

xml files searchable.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:hint="@string/search_hint" />

and a menu file: klassenliste.xml

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
<item android:id="@+id/search"
    android:title="@string/search_title"
    android:icon="@drawable/ic_btn_search"
    android:showAsAction="collapseActionView|ifRoom"
    android:actionViewClass="android.widget.SearchView"></item>

1 Answers1

0

The actual "sending" of the search query is done with the assistance of the Android system itself. That said, you still need to specify which activity to launch to process and display the search query.

Assume that SearchActivity is your target activity for showing/processing search queries. See my answer here. Also, your onCreateOptionsMenu(Menu menu) method seems to be missing important lines of code. Refer the docs. Use a SearchView if developing for Android 3.0+ and using an ActionBar.

Community
  • 1
  • 1
Kedar Paranjape
  • 1,822
  • 2
  • 22
  • 33