當前位置:首頁 » 安卓系統 » android搜索提示

android搜索提示

發布時間: 2022-11-19 06:18:07

㈠ 請教android的EditText怎麼實現類似搜索引擎的輸入提示

那就是用AutoCompleteTextView這個控制項 它要綁定一個adapter下拉列表的適配器和數據 具用法你自己看android的api吧

㈡ Android的搜索框怎麼加入提示文字

首先引入一下jquery。
然後通過jquery選擇器綁定單擊事件
給文獻檢索這一項加一個ID 比如 <li id="book">文獻檢索</li>
$('#book').click(function(){
$this.css('color','blue') //點擊變藍

window.location = 'www..com'//跳轉到網路界面

㈢ Android如何實現百度搜索欄的下拉提示效果啊求組 急!

這是一種類似搜索引擎索引的提示方式,要麼自己做一套,要麼使用共用的,簡單一點的話,在資料庫用模糊搜索也可以~~

㈣ 請教android的EditText怎麼實現類似搜索引擎的輸入提示

Android中有個控制項叫AutoCompleteTextview就是用於輸出過慮下拉顯示用的控制項.類似搜索引擎中的輸入提示的功能.

㈤ android怎麼使用SearchView啊

SearchView即時搜索提示功能,主要實現如下:
layout布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:iconifiedByDefault="true"
android:inputType="textCapWords"
android:imeOptions="actionSearch"
android:queryHint="" />
</RelativeLayout>

xml中主要配置有四個屬性,如下:
android:iconifiedByDefault表示搜索圖標是否在輸入框內。true效果更加
android:imeOptions設置IME options,即輸入法的回車鍵的功能,可以是搜索、下一個、發送、完成等等。這里actionSearch表示搜索
android:inputType輸入框文本類型,可控制輸入法鍵盤樣式,如numberPassword即為數字密碼樣式
android:queryHint輸入框默認文本

SearchView的幾個主要函數
setOnCloseListener(SearchView.OnCloseListener listener)表示點擊取消按鈕listener,默認點擊搜索輸入框
setOnQueryTextListener(SearchView.OnQueryTextListener listener)表示輸入框文字listener,包括public boolean onQueryTextSubmit(String query)開始搜索listener,public boolean onQueryTextChange(String newText)輸入框內容變化listener,兩個函數

java部分實現:
package cn.trinea.android.demo;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheledExecutorService;
import java.util.concurrent.ScheledFuture;
import java.util.concurrent.TimeUnit;

import android.app.ActionBar;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.SearchView;
import android.widget.SearchView.OnCloseListener;
import android.widget.Toast;
public class SearchViewDemo extends Activity {
private SearchView searchView;
private Context context;
private MyHandler handler;
// schele executor
private ScheledExecutorService scheledExecutor = Executors.newScheledThreadPool(10);
private String currentSearchTip;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_view_demo);
context = getApplicationContext();
handler = new MyHandler();
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP
| ActionBar.DISPLAY_SHOW_CUSTOM);
setTitle(" ");
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customActionBarView = inflater.inflate(R.layout.search_view_demo_title, null);
searchView = (SearchView)customActionBarView.findViewById(R.id.search_view);
searchView.setIconified(false);
searchView.setOnCloseListener(new OnCloseListener() {
@Override
public boolean onClose() {
// to avoid click x button and the edittext hidden
return true;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
public boolean onQueryTextSubmit(String query) {
Toast.makeText(context, "begin search", Toast.LENGTH_SHORT).show();
return true;
}
public boolean onQueryTextChange(String newText) {
if (newText != null && newText.length() > 0) {
currentSearchTip = newText;
showSearchTip(newText);
}
return true;
}
});
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL
| Gravity.RIGHT);
actionBar.setCustomView(customActionBarView, params);
// show keyboard
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
public void showSearchTip(String newText) {
// excute after 500ms, and when excute, judge current search tip and newText
schele(new SearchTipThread(newText), 500);
}
class SearchTipThread implements Runnable {
String newText;
public SearchTipThread(String newText){
this.newText = newText;
}
public void run() {
// keep only one thread to load current search tip, u can get data from network here
if (newText != null && newText.equals(currentSearchTip)) {
handler.sendMessage(handler.obtainMessage(1, newText + " search tip"));
}
}
}
public ScheledFuture<?> schele(Runnable command, long delayTimeMills) {
return scheledExecutor.schele(command, delayTimeMills, TimeUnit.MILLISECONDS);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
onBackPressed();
return true;
}
}
return false;
}
private class MyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
Toast.makeText(context, (String)msg.obj, Toast.LENGTH_SHORT).show();
break;
}
}
}
}
上面代碼在onQueryTextChange函數即輸入框內容每次變化時將一個數據獲取線程SearchTipThread放到ScheledExecutorService中,500ms後執行,在線程執行時判斷當前輸入框內容和要搜索內容,若相等則繼續執行,否則直接返回,避免不必要的數據獲取和多個搜索提示同時出現。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
表示默認輸入法彈出

編輯框內容為空點擊取消的x按鈕,編輯框收縮,可在onClose中返回true

Java

1
2
3
4
5
6
7

searchView.setOnCloseListener(new OnCloseListener() {

@Override
public boolean onClose() {
return true;
}
});

searchView.onActionViewExpanded();表示在內容為空時不顯示取消的x按鈕,內容不為空時顯示.
searchView.setSubmitButtonEnabled(true);編輯框後顯示search按鈕,個人建議用android:imeOptions=」actionSearch」代替。
隱藏輸入法鍵盤
InputMethodManager inputMethodManager;
inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

private void hideSoftInput() {
if (inputMethodManager != null) {
View v = SearchActivity.this.getCurrentFocus();
if (v == null) {
return;
}
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
searchView.clearFocus();
}
}

其中SearchActivity為Activity的類名

㈥ android 一般 搜索框 是用searchview 嗎

1、SearchView是搜索框組件,它可以讓用戶在文本框里輸入文字,通過監聽器取得用戶的輸入,當用戶點擊搜索時,監聽器執行實際的搜索。 2、SearchView組件的常用方法如下: ①setIconifiedByDefault(boolean iconified) ===> 設置搜索框默認是否自動縮小為圖標。 ②setOnQueryTextListener(SearchView,OnQueryTextListener listener) ===> 為搜索框設置監聽器 ③setSubmitButtonEnabled(boolean enabled) ===> 設置是否顯示搜索按鈕 ④setQueryHint(CharSequence hint) ===> 設置搜索框內的默認顯示的提示文本 3、為SearchView增加一個配套的ListView,則可以為其增加自動完成的功能,即ListView用於為SearchView顯示自動補齊列表 4、具體實現代碼如下: package org.crazyit.ui; import android.os.Bundle; import android.text.TextUtils; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SearchView; import android.widget.Toast; import android.app.Activity; public class SearchViewTest extends Activity implements SearchView.OnQueryTextListener { private SearchView sv; private ListView lv; // 自動完成的列表 private final String[] mStrings = { "aaaaa", "bbbbbb", "cccccc", "ddddddd" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lv = (ListView) findViewById(R.id.lv); lv.setAdapter(new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1, mStrings)); lv.setTextFilterEnabled(true);//設置lv可以被過慮 sv = (SearchView) findViewById(R.id.sv); // 設置該SearchView默認是否自動縮小為圖標 sv.setIconifiedByDefault(false); // 為該SearchView組件設置事件監聽器 sv.setOnQueryTextListener(this); // 設置該SearchView顯示搜索按鈕 sv.setSubmitButtonEnabled(true); // 設置該SearchView內默認顯示的提示文本 sv.setQueryHint("查找"); } // 用戶輸入字元時激發該方法 @Override public boolean onQueryTextChange(String newText) { Toast.makeText(SearchViewTest.this, "textChange--->" + newText, 1).show(); if (TextUtils.isEmpty(newText)) { // 清除ListView的過濾 lv.clearTextFilter(); } else { // 使用用戶輸入的內容對ListView的列表項進行過濾 lv.setFilterText(newText); } return true; } // 單擊搜索按鈕時激發該方法 @Override public boolean onQueryTextSubmit(String query) { // 實際應用中應該在該方法內執行實際查詢 // 此處僅使用Toast顯示用戶輸入的查詢內容 Toast.makeText(this, "您的選擇是:" + query, Toast.LENGTH_SHORT).show(); return false; } } </string>

㈦ android應用中的搜索功能怎麼實現的

在APP應用中啟用搜索
在app應用中,至少要執行如下的三個步驟,才能讓app應用能夠進行檢索。如果要提供搜索建議,還需要執行第4步:
編寫搜索配置的XML文件
編寫搜索的activity類
在Android的manifest.xml文件中,對兩面兩個步驟的工作進行配置。
如果要使用搜索建議,則需要增加一個contentprovider。
配置搜索的XML配置文件
首先看下如何配置搜索的XML配置文件。先命名配置文件名稱為searchable.xml,保存在res/xml文件夾中。然後需要設置搜索框的文本,並且應該增加一個hint的提示文本信息,如下代碼所示:
<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/search_label"> android:hint="@string/search_hint" </searchable>

關於搜索配置文件有很多的配置選項,建議參考Android的手冊可以獲得更多:
http://developer.android.com/guide/topics/search/searchable-config.html。
增加搜索的Activity
當用戶進行搜索時,Android調用activity進行搜索,代碼如下:
publicclass SampleSearchActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleIntent(getIntent()); }public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleIntent(getIntent()); } public void onNewIntent(Intent intent) { setIntent(intent); handleIntent(intent); } public void onListItemClick(ListView l, View v, int position, long id) { // 點每個搜索結果時的處理代碼 } private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); doSearch(query); } } private void doSearch(String queryStr) { //執行真正的查詢結果處理 } }

在上面的代碼中,在handleIntent方法中,當按下搜索按鈕,系統就會自動發送Intent,action是Intent.ACTION_SEARCH,然後通過intent.getStringExtra(SearchManager.QUERY);獲得要搜索的字元串。
其中為什麼要包含onNewIntent()方法呢?主要是因為Android的back後退機制。Android會默認把每一個新的activity放到activity棧的頂部。如果用戶點了後退鍵,則會關閉棧頂部的activity。嘗試考慮一種情況,用戶搜索一個內容並且系統列出了結果,如果用戶發現結果不是他所要的,或者希望重新檢索,則會重新點擊搜索按鍵,這樣將會產生一個新的搜索activity的實例,在activity棧中就會有兩個搜索的activity,這是開發者並不期待的,所以,需要將這個搜索的activity聲明為singleTop類型的activity,這樣的話,無論用戶按返回鍵還是盡心個多次的搜索,在acitivty棧中始終保持的是一個搜索activity的實例。因為當activity被設置為singleTop的載入模式時,如果堆棧的頂部已經存在了該Activity,那麼,它便不會重新創建,而是調用onNewIntent。如果,該Activity存在,但不是在頂部,那麼該Activity依然要重新創建。
mainifest配置文件
接下來,需要對manifest配置文件進行配置,必須要對其中進行如下配置:
搜索的activity.
使用搜索的intent
activity啟動模式
searchable.xml中的元數據
更多的定義搜索的元數據
下面是典型的一個搜索的配置
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".YourApp" > <meta-data android:name="android.app.default_searchable" android:value=".YourSearchActivity" /> <activity android:label="@string/app_name" android:launchMode="singleTop" android:name=".YourSearchActivity" > <intent-filter > <action android:name="android.intent.action.SEARCH" /> </intent-filter> <intent-filter > <action android:name="android.intent.action.VIEW" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> </application>

在上面的典型配置中,要注意如下幾點:
1)由於當調用搜索activity時,Android調用的是android.intent.action.SEARCH作為搜索的intent,所以必須在intent-filter中包含android.intent.action.SEARCH。
2)在<meta-data>中,指出了searchable.xml的位置
3)同樣在<meta-data>中,通過:
<meta-data android:name="android.app.default_searchable" android:value=".YourSearchActivity" />

指出了當執行搜索的字元串提交時,將調用哪一個activity去進行處理。

㈧ Android如何實現百度搜索欄的下拉提示效果啊求組 急!

用一個TextWatcher監聽,然後若有匹配的自定義一個下拉,並顯示

㈨ 怎麼使用android軟體的搜索功能

當你需要在你的應用程序中提供搜索服務時,通過使用Android的搜索框架,應用程序將顯示一個自定義搜索對話框來處理用戶的搜索請求。通過一個簡單的搜索按鈕或從您的應用程序中調用API,搜索對話框就會顯示在屏幕的頂部,並會自動顯示應用程序圖標。

本文將教你如何為你的應用程序提供一個自定義搜索對話框。這樣做,給您的用戶提供一個標准化的搜索體驗,並能增加如語音搜索和搜索建議等功能。

基礎知識

Android的搜索框架將代您管理的搜索對話框,您不需要自己去開發一個搜索框,不需要擔心要把搜索框放什麼位置,也不需要擔心搜索框影響您當前的界面。所有的這些工作都由SearchManager類來為您處理(以下簡稱「搜索管理器」),它管理的Android搜索對話框的整個生命周期,並執行您的應用程序將發送的搜索請求,返回相應的搜索關鍵字。

當用戶執行一個搜索,搜索管理器將使用一個專門的Intent把搜索查詢的關鍵字傳給您在配置文件中配置的處理搜索結果的Activity。從本質上講,所有你需要的就是一個Activity來接收Intent,然後執行搜索,並給出結果。具體來說,你需要的做的事就包括以下內容:

一個搜索配置
我們用個XML配置文件來對搜索對話框進行配置,包括一些功能的配置,如文本框,設置語音搜索和搜索建議中顯示的提示文字等。

一個用來處理搜索請求的Activity
這個Activity用來接收搜索查詢的內容,然後搜索您的數據並顯示搜索結果。

一種用戶執行搜索的途徑
默認情況下,一旦你配置了一個可搜索的Activity,設備搜索鍵(如果有)將調用搜索對話框。然而,你應該始終提供另一種手段,讓用戶可以調用搜索對話框,如在選項菜單中的搜索按鈕或其他用戶界面上的按鈕,因為不是所有的設備提供一個專門的搜索鍵。

創建一個搜索對話框配置文件

搜索框配置文件是一個用來配置您的應用程序中搜索框的設置的XML文件,這個文件一般命名為searchable.xml,並且必須保存在項目的res/xml/目錄下。

配置文件的根節點必須為,可以有一個或多個屬性。

㈩ Android中如何讓一個EditView被點擊後出現搜索框,搜索框已經實現

Android有自帶的一個控制項AutoCompleteTextView

具體用法如下:

main.xml代碼如下:

<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="請選擇你喜歡的歌曲"
android:completionThreshold="1"
android:dropDownHorizontalOffset="20dp"
android:ems="10"
android:text="AutoCompleteTextView">

<requestFocus/>
</AutoCompleteTextView>

</LinearLayout>

java代碼為:

importandroid.app.Activity;
importandroid.graphics.Bitmap;
importandroid.graphics.BitmapFactory;
importandroid.graphics.drawable.BitmapDrawable;
importandroid.os.Bundle;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.View.OnTouchListener;
importandroid.widget.ArrayAdapter;
importandroid.widget.AutoCompleteTextView;
importandroid.widget.Button;
importandroid.widget.ImageView;

{

//定義字元串數組作為提示的文本
String[]books=newString[]{"rollen","rollenholt","rollenren","roll"};

@Override
protectedvoidonCreate(BundlesavedInstanceState){
//TODOAuto-generatedmethodstub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//創建一個ArrayAdapter封裝數組
ArrayAdapter<String>av=newArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,books);
AutoCompleteTextViewauto=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
auto.setAdapter(av);
}
}
熱點內容
安卓網頁圖片不顯示怎麼辦 發布:2024-05-02 13:16:00 瀏覽:672
虛擬機搭建linux 發布:2024-05-02 13:02:48 瀏覽:186
哈弗f7配置怎麼使用 發布:2024-05-02 12:53:14 瀏覽:575
psv重新構建資料庫 發布:2024-05-02 12:43:53 瀏覽:792
農行對公密碼器的憑證號碼在哪裡 發布:2024-05-02 12:38:55 瀏覽:890
雙子星腳本 發布:2024-05-02 12:26:01 瀏覽:142
域名如何將程序部署到伺服器 發布:2024-05-02 12:25:38 瀏覽:948
命令行編譯lex 發布:2024-05-02 12:17:25 瀏覽:61
linux讀u盤 發布:2024-05-02 11:49:37 瀏覽:782
android圖片點擊全屏 發布:2024-05-02 11:48:55 瀏覽:432