Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot get searchview in actionbar to work
    primarykey
    data
    text
    <p>I am pretty new to java and android development; and I have been working on an app in which I want an action bar with a <code>SearchView</code>. I have looked at the google examples but I can not get it to work. I must be doing something wrong and I'm about to give up on app-development :D I have searched but I have not found anything helpful. Maybe you guys can help me :)</p> <p><strong>The problem</strong>: I get the search view to open as it should, but after that nothing happens at all, I've noticed that my <em>searchManager.getSearchableInfo(getComponentName())</em> returns null. Also my hint that I've given is not displayed in my search box which leads me to believing that maybe the app can't find my searchable.xml? Enough talk :)</p> <p><strong>MainActivity.java</strong></p> <pre><code>public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName())); return true; } } </code></pre> <p><strong>searchable.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;searchable xmlns:android="http://schemas.android.com/apk/res/android" android:hint="@string/search_hint" android:label="@string/app_label"&gt; &lt;/searchable&gt; </code></pre> <p><strong>Androidmanifest</strong></p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.searchapp" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".SearchableActivity" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.SEARCH" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".MainActivity" android:label="@string/title_activity_main" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p><strong>SearchableActivity.java</strong></p> <pre><code>package com.example.searchapp; import android.app.ListActivity; import android.app.SearchManager; import android.content.Intent; import android.os.Bundle; import android.util.Log; public class SearchableActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search); // Get the intent, verify the action and get the query Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); doMySearch(query); } } private void doMySearch(String query) { Log.d("Event",query); } } </code></pre> <p>And here is a link to the referred project, I would be eternally grateful if someone was to help me with this!</p> <p><a href="https://www.dropbox.com/sh/z0amwhu16y1essw/Tjko051u9x/SearchApp.rar" rel="nofollow noreferrer">Source code</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload