Android中的AutoCompleteTextView(隨筆提示文本)組件的簡單使用,

來源:互聯網
上載者:User

Android中的AutoCompleteTextView(隨筆提示文本)組件的簡單使用,

  Android中的隨筆提示文本組件AutoCompleteTextView的使用,此組件用於輸入文本,然後就會在所配置的適配器中的資料進行尋找顯示在組件下面。

  這裡值得注意的是AutoCompleteTextView使用時,你使用一個字元是沒有反應的,你至少要輸入兩個字元以上才有反應。

  本文只做記錄作用,有差錯的地方望指出《黑幕下的人》

                     

java代碼

package cn.hmxin.autocompletetext;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;public class MainActivity extends ActionBarActivity {    private AutoCompleteTextView autoText = null ;//聲明AutoCompleteTextView對象,用於綁定布局檔案中的組件    private ArrayAdapter<String> adapter = null ;//聲明ArrayAdapter對象《適配器》    //聲明並執行個體化一個String數組,放在適配器中    String[] strs = new String[] {"C", "C++", "Java", "JavaWeb", "JavaScript", "Visual Basic", "彙編", "python", "Android"};    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        autoText = (AutoCompleteTextView)findViewById(R.id.autotext);//綁定組件        //執行個體化適配器,並設定其資料        adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_dropdown_item_1line, strs);        autoText.setAdapter(adapter);//設定autoText對象中的適配器為adapter    }}

xml代碼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="cn.hmxin.autocompletetext.MainActivity" >    <AutoCompleteTextView        android:id="@+id/autotext"        android:layout_width="match_parent"        android:layout_height="wrap_content"/></LinearLayout>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.