android - SearchView not searching -


i trying implement search functionality in android app using searchview within layout of app. purposefully chose have in layout rather in action bar.

the problem once type search text , hit enter/search key on keyboard nothing happens. searchable intent never called. feel must missing causing search not trigger

i apologize if haven't included code in correct format below. please let me know if there additional information help. in advance!

manifest

<uses-sdk     android:minsdkversion="11"     android:targetsdkversion="17" /> <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_network_state"/>  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.lotr.arda.mainactivity"         android:label="@string/app_name" >      </activity>     <activity         android:name=".webactivity"         android:theme="@android:style/theme.notitlebar" >       </activity>          <activity         android:name=".menuactivity"         android:theme="@android:style/theme.notitlebar" >          <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>       </activity>       <activity android:name="com.google.ads.adactivity" android:configchanges="keyboard|keyboardhidden|orientation|screenlayout|uimode|screensize|smallestscreensize">         </activity>          <activity android:name=".searchactivity" >     <intent-filter>         <action android:name="android.intent.action.search" />     </intent-filter>     <meta-data android:name="android.app.searchable"                android:resource="@xml/searchable"/> </activity> </application> </manifest> 

res/xml/search

<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/searchhint" > </searchable> 

searchactivity.java

package com.lotr.arda;  import android.app.listactivity; import android.app.searchmanager; import android.content.intent; import android.os.bundle;  public class searchactivity extends listactivity{  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.search_page);      // intent, verify action , query     intent intent = getintent();     if (intent.action_search.equals(intent.getaction())) {       string query = intent.getstringextra(searchmanager.query);        system.out.println(query);       //domysearch(query);     } } } 

menuactivity.java (layout searchview located)

package com.lotr.arda;  import com.google.ads.adrequest; import com.google.ads.adview; import android.app.activity; import android.app.searchmanager; import android.app.searchableinfo; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.searchview;    public class menuactivity extends activity {      public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.menu_page);     try{              adview myad = (adview) findviewbyid(r.id.ad);          adrequest adrequest = new adrequest();            myad.loadad(adrequest);           searchmanager searchmanager = (searchmanager)getsystemservice(search_service);          searchableinfo searchableinfo = searchmanager.getsearchableinfo(getcomponentname());           searchview sv = (searchview)findviewbyid(r.id.searchview1);          sv.setsearchableinfo(searchableinfo);           button alpha = (button)this.findviewbyid(r.id.button1);          alpha.setonclicklistener(new view.onclicklistener() {                 public void onclick(view v) {                        intent intent = new intent(menuactivity.this, mainactivity.class);                         startactivity(intent);                                       }});                 }catch(exception e) {system.out.println(e.tostring());}     } } 

you missing searchview#setonquerytextlistener. you'll need override onquerytextsubmit() method perform , handle search.

edit: assuming you're querying database , using cursor results.

msearchview.setonquerytextlistener(new onquerytextlistener()     {         @override         public void onquerytextsubmit(string query) {             cursor c = getcontentresolver.query(uri, null, "col_1 = ? or col_2 = ?", new string[] { query, query }, null);             //do whatever want cursor here         }     } ); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -