答案 0 :(得分:1)
对于多个世界,您需要使用 MultiAutoCompleteView 将下面的代码放在布局文件中。
<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_below="@+id/autoCompleteTextView1"
android:layout_alignLeft="@+id/autoCompleteTextView1"
android:layout_alignStart="@+id/autoCompleteTextView1"
android:hint="Multi Auto Complete " />
在Java文件中
public class MainActivity extends Activity {
MultiAutoCompleteTextView text2;
String[] color={"Blue","Black","some color","some color","some color","some color"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text2=(MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,color);
text2.setAdapter(adapter);
text2.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}
答案 1 :(得分:0)
请使用两个 AutoCompleteTextView 而不是EditText。 在布局文件中,将垂直LinearLayout之间的代码放在下面,或根据您的需要。
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:ems="10" >
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:ems="10" >
在java文件中放置代码
public class MainActivity extends Activity {
AutoCompleteTextView text,text1;
String[] str={"Color","some text","some text","some text","some text","some text"};
String[] color={"Blue","Black","some color","some color","some color","some color"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
text1=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView2);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,str);
ArrayAdapter colorAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,color);
text.setAdapter(adapter);
text.setThreshold(1);
text1.setAdapter(colorAdapter);
text1.setThreshold(1);
}
}