最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應(yīng)用示例

 更新時(shí)間:2016年10月27日 11:44:44   作者:Android_Tutor  
這篇文章主要介紹了Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應(yīng)用,結(jié)合實(shí)例形式分析了AutoCompleteTextView Widget使用步驟與相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應(yīng)用。分享給大家供大家參考,具體如下:

現(xiàn)在我們上網(wǎng)幾乎都會用百度或者谷歌搜索信息,當(dāng)我們在輸入框里輸入一兩個(gè)字后,就會自動提示我們想要的信息,這種效果在Android 里是如何實(shí)現(xiàn)的呢? 事實(shí)上,Android 的AutoCompleteTextView Widget ,只要搭配ArrayAdapter 就能設(shè)計(jì)同類似Google 搜索提示的效果.

本例子先在Layout 當(dāng)中布局一個(gè)AutoCompleteTextView Widget ,然后通過預(yù)先設(shè)置好的字符串?dāng)?shù)組,將此字符串?dāng)?shù)組放入ArrayAdapter ,最后利用AutoCompleteTextView.setAdapter 方法,就可以讓AutoCompleteTextView 具有自動提示的功能.例如,只要輸入ab ,就會自動帶出包含ab 的所有字符串列表.

讓我們看一下效果圖:

下面是我們程序所涉及變動的代碼(本例子代碼寫的相對較少):

首先是main.xml:

<?xml version="1.0" encoding="utf-8"?>
<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="Please input:"
  />
<AutoCompleteTextView
  android:id="@+id/actv"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
/>
</LinearLayout>

其次是主控制程序AutoCompleteTextViewDemo.Java:

package com.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class AutoCompleteTextViewDemo extends Activity {
  private AutoCompleteTextView actv;
  private static final String[] autoStrs = new String[]{"a","abc","abcd","abcde","ba"};
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //通過findViewById()方法取到actv
    actv = (AutoCompleteTextView)findViewById(R.id.actv);
    //new ArrayAdapter對象并將autoStr字符串?dāng)?shù)組傳入actv中
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_dropdown_item_1line,autoStrs);
    actv.setAdapter(adapter);
  }
}

所有程序就這么一點(diǎn)點(diǎn)哦,大功就這么告成了,最后執(zhí)行之,將達(dá)到上述效果。

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論

临城县| 抚顺市| 南乐县| 建湖县| 长宁县| 武平县| 承德县| 临洮县| 阿克| 克东县| 清原| 鄯善县| 巫山县| 阿图什市| 乌鲁木齐市| 尼木县| 威海市| 甘南县| 博兴县| 塔河县| 宜丰县| 石门县| 阿拉尔市| 吴川市| 怀安县| 曲周县| 黑山县| 新绛县| 姜堰市| 阿荣旗| 渑池县| 灵台县| 北京市| 哈巴河县| 隆子县| 乳源| 出国| 江永县| 毕节市| 龙泉市| 高邑县|