2.4.1 自动完成文本框
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layoutMain" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <AutoCompleteTextView android:id="@+id/movie" android:layout_width="match_parent" android:layout_height="wrap_content" android:completionHint="请选择你喜欢的电影" android:completionThreshold="1" android:text="" > <requestFocus /> </AutoCompleteTextView> </LinearLayout>
package com.moon.hello2; import android.R.anim; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class MainActivity extends Activity { String[] movies = new String[]{"黑客帝国","星球大战","侏罗纪公园","复仇者联盟","蝙蝠侠"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_main); AutoCompleteTextView movieView = (AutoCompleteTextView)findViewById(R.id.movie); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,movies); movieView.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
本篇文章首发自魔芋红茶的博客https://www.cnblogs.com/Moon-Face/
请尊重其他人的劳动成功,转载请注明。