<MultiAutoCompleteTextView android:id="@+id/multiAutoCompleteTextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:completionThreshold="1" > </MultiAutoCompleteTextView>
<RelativeLayout 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" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="135dp" android:text="Button" /> <MultiAutoCompleteTextView android:id="@+id/multiAutoCompleteTextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="68dp" android:completionThreshold="1" android:ems="10" > <requestFocus /> </MultiAutoCompleteTextView> </RelativeLayout>
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.MultiAutoCompleteTextView; import android.widget.Button; import android.widget.Toast; import android.widget.ArrayAdapter; import java.util.ArrayList; import java.util.List; public class MainActivity extends Activity { private static final String[] COUNTRIES = new String[] { "Belgium", "France", "Italy", "Germany", "Spain", "Thailand", "Taiwan" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // multiAutoCompleteTextView1 final MultiAutoCompleteTextView MultiAutocomplete1 = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES); MultiAutocomplete1.setAdapter(adapter); MultiAutocomplete1.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); // button1 final Button btn1 = (Button)findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(MainActivity.this, String.valueOf("Your Input : " + MultiAutocomplete1.getText().toString()), Toast.LENGTH_SHORT).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท