AutoCompleteTextView

自动匹配输入

layout部分:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/textview_inputshow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_x="10dip"
        android:layout_y="10dip"
        android:text="@string/pleaseinput"
        android:textSize="25sp" />


    <AutoCompleteTextView
        android:id="@+id/auto_complete"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:layout_x="10dip"
        android:layout_y="50dip"
        android:textColor="#000000"
        android:textSize="25sp" />


    <Button
        android:id="@+id/cleanButton"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_x="10dip"
        android:layout_y="150dip"
        android:text="清空"
        android:textSize="25sp" >
    </Button>


</AbsoluteLayout>



代码部分:

private AutoCompleteTextView autocomplete;
private Button cleanButton;
static final String[] COUNTRIES = new String[] { "China", "Russia",
"Germany", "Ukraine", "Belarus", "USA", "China1", "China12",
"Germany", "Russia2", "Belarus", "USA", "UAA", "UBC", "UBB", "CCC",
"BBB", "广州1", "广州2", "广州3", "广州4", "广东1", "广东2", "广东3", };


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.auto_complete_text_view);
setTitle("AutoCompleteTextView");


autocomplete = (AutoCompleteTextView) findViewById(R.id.auto_complete);
cleanButton = (Button) findViewById(R.id.cleanButton);


ArrayAdapter<String> adapter = new ArrayAdapter<String>(
AutoCompleteTextViewActivity.this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
autocomplete.setAdapter(adapter);


cleanButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
autocomplete.setText("");
}
});
}


你可能感兴趣的:(android,String,autocomplete,layout,dropdown,button)