如何设置适配器自动完成文字? [英] How to set Adapter to Auto Complete Text view?
本文介绍了如何设置适配器自动完成文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要适配器的数据设置为机器人自动完成文本视图。
I need adapter data set to the auto complete text view in android .
推荐答案
为 AutoCompleteTextView
创建一个项目并粘贴code到需要的地方 -
Create one project for AutoCompleteTextView
and paste the code to required place -
的main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<AutoCompleteTextView android:id="@+id/myautocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
/>
</LinearLayout>
AutoCompleteTextview.java
public class AndroidAutoCompleteTextView extends Activity implements TextWatcher{
AutoCompleteTextView myAutoComplete;
String item[]={
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myAutoComplete = (AutoCompleteTextView)findViewById(R.id.myautocomplete);
myAutoComplete.addTextChangedListener(this);
myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, item));
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
}
只要用这个例子。而且,弄清楚他们是如何设置适配器自动完成的TextView
希望这有助于你。
这篇关于如何设置适配器自动完成文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文