欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

android中的search dialog

系統(tǒng) 3041 0
如果你要在你的應用程序中實現(xiàn)搜索功能,android中為用戶提供兩種搜索的特性:
一種是search dialog,另一種是search widget.
由于search widget要在3.0以上的版本才能使用。這里只講search dialog
search dialog是由android系統(tǒng)控制的。需要由用戶去激活它。并且搜索框只出現(xiàn)在activity的最頂部。當提交查詢的數(shù)據(jù)時,系統(tǒng)會轉發(fā)給一個activity進行處理。用戶也可以保存最近查詢的數(shù)據(jù)。這里講一下基本的配置。
1.新建一個位于res/xml下的一個searchable.xml的配置文件
    
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
	<!-- label為搜索框上方的文本,hint搜索框里面的提示文本  -->
	android:label="@string/search_label"
	android:hint="@string/search_hint"
	android:icon="@drawable/search32"
	android:searchMode="showSearchLabelAsBadge"
	
	<!-- 中間是語音搜索配置(看不懂....) -->
	android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
	android:voiceLanguageModel="free_form"
	android:voicePromptText="Invoke Search"
	<!-- 這里的值必須SearchSuggestionSampleProvider.AUTHORITY相同,后面講 -->
	android:searchSuggestAuthority="SuggestionProvider"	
	android:searchSuggestSelection=" ? ">    
</searchable>

  


2.新建一個activity:SearchInvoke.java。此activity的作用是用來啟動search dialog并把要查詢的數(shù)據(jù)進行轉發(fā)給另一個activity進行處理。
關鍵代碼:
    
public class SearchInvoke extends Activity{
	private Button mStartSearch;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_invoke);
		//就一個按鈕
		mStartSearch = (Button)findViewById(R.id.btn_start_search);
		//啟動搜索框
		mStartSearch.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				onSearchRequested();
			}
		});
	}

        //重寫onSearchRequested方法
	@Override
	public boolean onSearchRequested() {
               //除了輸入查詢的值,還可額外綁定一些數(shù)據(jù)
		Bundle appSearchData = new Bundle();
		appSearchData.putString("demo_key","text");
		
		startSearch(null, false, appSearchData, false); 
                //必須返回true。否則綁定的數(shù)據(jù)作廢
		return true;
	}	

}

  


3.處理activity--》SearchQueryResults.java
    
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_query_results);

        //兩個TextView進行數(shù)據(jù)顯示
        mQueryText = (TextView) findViewById(R.id.txt_query);
        mAppDataText = (TextView) findViewById(R.id.txt_appdata);

        final Intent queryIntent = getIntent();
        final String queryAction = queryIntent.getAction();
        if (Intent.ACTION_SEARCH.equals(queryAction)) {
            doSearchQuery(queryIntent, "onCreate()");
        }
        else {
            mDeliveredByText.setText("onCreate(), but no ACTION_SEARCH intent");
        }
    }

    /** 
     * Called when new intent is delivered.
       這個方法不知道何時調用。看了文檔說在manifest中配置此activity的啟動模式為singleTop。不過試了貌似還沒有執(zhí)行到此方法
     */
    @Override
    public void onNewIntent(final Intent newIntent) {
        super.onNewIntent(newIntent);
        Log.i(TAG, "SearchQueryResults-->onNewIntent()");
        // get and process search query here
        final Intent queryIntent = getIntent();
        final String queryAction = queryIntent.getAction();
        if (Intent.ACTION_SEARCH.equals(queryAction)) {
            doSearchQuery(queryIntent, "onNewIntent()");
        }
        else {
            mDeliveredByText.setText("onNewIntent(), but no ACTION_SEARCH intent");
        }
    }

    //處理
    private void doSearchQuery(final Intent queryIntent, final String entryPoint) {

        //獲取查詢的值  
        final String queryString = queryIntent.getStringExtra(SearchManager.QUERY);
        mQueryText.setText(queryString);

        //保存查詢的值,這樣在下次搜索的時候會有以前搜索數(shù)據(jù)的提示
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, 
                SearchSuggestionSampleProvider.AUTHORITY, SearchSuggestionSampleProvider.MODE);
        suggestions.saveRecentQuery(queryString, null);
        
        //獲得額外遞送過來的值
        final Bundle appData = queryIntent.getBundleExtra(SearchManager.APP_DATA);
        if (appData == null) {
            mAppDataText.setText("<no app data bundle>");
        }
        if (appData != null) {
            String testStr = appData.getString("demo_key");
            mAppDataText.setText((testStr == null) ? "<no app data>" : testStr);
        }
    }

  


3.創(chuàng)建類SearchSuggestionSampleProvider.java用戶查詢數(shù)據(jù)保存的配置信息
    
public class SearchSuggestionSampleProvider extends
        SearchRecentSuggestionsProvider {

    final static String AUTHORITY="SuggestionProvider";
    final static int MODE=DATABASE_MODE_QUERIES;
    
    public SearchSuggestionSampleProvider(){
        super();
        setupSuggestions(AUTHORITY, MODE);
    }
}

  


4.最重要的一步,在AndroidManifest.xml中的配置
    
<!-- search ui -->
		 <activity android:name="com.zyz.app.SearchQueryResults"
                  android:label="處理查詢結果">
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>
            <meta-data android:name="android.app.searchable"
                       android:resource="@xml/searchable" />
       	 </activity>
        <!--此activity用來輸入并遞送結果,meta-data必須配置-->
       	 <activity android:name="com.zyz.app.SearchInvoke">
       	 	<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="com.zyz.app.SearchQueryResults"/>
       	 </activity>
       <!--provider的注冊-->
        <provider android:name="com.zyz.app.SearchSuggestionSampleProvider"
                  android:authorities="SuggestionProvider" />

  


5.無圖無真相

android中的search dialog

android中的search dialog


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲精品人成网在线播放影院 | 亚洲精品一区二区三区在线 | 亚洲精品久 | 九色91| 欧美性色生活片免费播放 | 欧美激情第二页 | 久久视频这里只精品99 | 国产精品成人国产乱一区 | 亚洲综合精品成人 | 精品一区二区在线观看视频 | 亚洲一区二区三区91 | 青娱乐九色 | 色欲AV蜜臀AV在线观看麻豆 | 中文字幕在线电影观看 | 欧美精品一区二区三区在线 | 激情亚洲 | 涩涩97| 香港三级台湾三级在线播放徐 | 91成人在线网站 | 国产日韩一区在线精品欧美玲 | 天天更新天天久久久更新影院 | 天天射天天干天天插 | va在线播放| 久久伊人中文字幕有码 | α片毛片 | 欧美精选在线 | 999热这里只有精品 三级在线网站 | 国产伦精品 | 91看片在线看片 | 四虎影视在线看免费完整版 | 色狠狠色狠狠综合一区 | 欧美福利视频一区二区三区 | 久久精品一区二区三区四区 | 亚洲精品AV无码喷奶水糖心 | 亚洲高清在线看 | 奇米影视555 | 欧美日韩一二三区 | 欧美成人一区二区三区 | 久久精品夜夜夜夜夜久久 | 欧美日日射 | 国产在线视频色综合 |