Android基礎TOP5_1:AutoCompleteTextView自動補全文字框

來源:互聯網
上載者:User

標籤:http   create   draw   code   ima   super   array   opd   hint   

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:orientation="vertical" 5     android:layout_height="match_parent" 6     tools:context="com.example.top5_1.MainActivity" > 7  8    <EditText 9         android:layout_width="fill_parent"10         android:layout_height="wrap_content"11         android:paddingLeft="5dp"12         android:background="#FFA500"13         android:textSize="16sp"14         android:drawableLeft="@drawable/ic_launcher"15         android:text="單詞搜尋補全示範" />16    <AutoCompleteTextView17       android:id="@+id/ed"18       android:layout_width="fill_parent"19       android:layout_height="wrap_content"20       style="@android:attr/textViewStyle"21       android:hint="請輸入單詞"
//設定從第二個字元開始提示22 android:completionThreshold="2"23 android:layout_marginTop="10dp"24 25 /></LinearLayout>

JAVA:

 1 public class MainActivity extends Activity{ 2 private AutoCompleteTextView act; 3 //設定資料來源 4 private static final String[] words={"abc","acd","ade"}; 5  6 protected void onCreate(Bundle savedInstanceState) { 7         super.onCreate(savedInstanceState); 8         setContentView(R.layout.activity_main); 9         act=(AutoCompleteTextView) findViewById(R.id.ed);10         //將資料來源賦到文字框11     ArrayAdapter<String> aa=new ArrayAdapter<String>(this,12             android.R.layout.simple_dropdown_item_1line,words);13     act.setAdapter(aa);14     };

 

Android基礎TOP5_1:AutoCompleteTextView自動補全文字框

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.