android传递包与搜索

您好我使用的是 android 3.0搜索小部件(不是搜索模式),问题是我需要传递一些参数和搜索词.

Android没有调用任何这些

searchManager.setondismissListener( new OndismissListener() {

            @Override
            public void ondismiss() {
                // Todo Auto-generated method stub
                Log.v(MyApp.TAG,"on dismiss search");

            }
        });

        searchManager.setonCancelListener( new OnCancelListener() {

            @Override
            public void onCancel() {
                // Todo Auto-generated method stub
                Log.v(MyApp.TAG,"on dismiss cancel");

            }
        });

@Override
    public boolean onSearchRequested() {
        Bundle appData = new Bundle();
        appData.putLong("listino_id",this.listino_id);
        this.startSearch(null,true,appData,false);
        return true;
        // return super.onSearchRequested();
    }

我需要我的活动不是singleOnTop,
这是我的AndroidManifest.xml

<activity android:name=".activity.ListinoprodottiActivity" android:windowSoftInputMode="stateHidden">


             <!-- Receives the search request. -->
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <!-- No category needed,because the Intent will specify this class component-->
            </intent-filter>

                   <!-- enable the base activity to send searches to itself -->
            <Meta-data android:name="android.app.default_searchable"
              android:value=".activity.ListinoprodottiActivity" />


            <!-- Points to searchable Meta data. -->
            <Meta-data android:name="android.app.searchable"
                       android:resource="@xml/searchable" />

        </activity>

这是我的searchable.xml

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

解决方法

在Search Widget中使用bundle传递数据:

layout / main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />
    <Button android:id="@+id/button" android:text="test"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>

layout / searchable.xml:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_label"
    android:hint="@string/search_hint" 
    android:searchMode="showSearchLabelAsBadge"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:voiceLanguageModel="free_form"
    android:voicePromptText="@string/search_invoke"
    android:searchSuggestSelection=" ? "
/>

values / strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World,SearchTest!</string>
<string name="app_name">Searchtest</string>
<string name="search_label">Search Test</string>
<string name="search_hint">1234</string>
<string name="search_invoke">234</string>
<string name="search_query_results">544545</string>
</resources>

AndroidManifest.xml:

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".SearchWidgetExampleTest" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <Meta-data android:name="android.app.default_searchable"
                       android:value=".ResultActivty" />
        </activity>

         <activity android:name=".ResultActivty"
                  android:label="@string/search_query_results">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <Meta-data android:name="android.app.searchable"
                       android:resource="@layout/searchable" />
        </activity>
    </application>

ResultActivty.java:

package org.imranandroid.TestSearchexmp;
import android.app.Activity;
import android.app.SearchManager;
import android.os.Bundle;
import android.widget.Toast;

public class ResultActivty extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Bundle bundled= getIntent().getBundleExtra(SearchManager.APP_DATA);
        Long ttdata=bundled.getLong("listino_id");
        Toast.makeText(this,ttdata.toString(),Toast.LENGTH_SHORT).show();
    }
}

SearchWidgetExampleTest.java:

package org.imranandroid.TestSearchexmp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SearchWidgetExampleTest extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button1 = (Button) findViewById(R.id.button);
        button1.setonClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onSearchRequested();
            }
        });
    }
    @Override
    public boolean onSearchRequested() {
        Bundle appDataBundle = new Bundle();
        appDataBundle.putLong("listino_id",4434724724L);
        startSearch("imran",false,appDataBundle,false);
        return true;
    }
}

快乐编码!!!

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...