Android輸入框中提示自動輸入內容

main.xml中內容

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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/autoCompleteTextView" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:hint="請輸入信息"/> 
</LinearLayout>

 

AutoCompleteTextView 類中內容

public class AutoCompleteTextView extends Activity {

 private AutoCompleteTextView autoCompleteTextView;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
  ArrayAdapter adapter = new ArrayAdapter(ZiDongTiShiActivity.this,
    android.R.layout.simple_dropdown_item_1line, autoStr);
  autoCompleteTextView.setAdapter(adapter);
 }
 private String[] autoStr = new String[] { "ab", "abc", "abcd", "def" };
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章