大佬教程收集整理的这篇文章主要介绍了在Android中自动完成文本?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
String search[] = {"one","two","three","four","five","six","seven","fifty"}; ArrayAdapter<String> adp= new ArrayAdapter<String>(this,R.layout.searchtext,search); search_item.setThreshold(1); search_item.setAdapter(adp);
这里我有像这样的数组:
private static final String[] COUNTRIES = new String[] { "Belgium","France","France_","Italy","GeRMANy","Spain","abcf","FFa","FFb","bFF","aFF" };
当我搜索ff然后它只给我2(“FFa”,“FFb”)建议不是4(“FFa”,“FFb”,“bFF”,“aFF”)
我在ActionBar中使用过它.你也可以在布局中使用它.因为它在ActionBar中的自定义布局.
public class TestActivity extends Activity { /** Called when the activity is first created. */ private static final String[] COUNTRIES = new String[] { "Belgium","aFF" }; @Override public void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); setContentView(R.layout.activity_main); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowCustomEnabled(true); // actionBar.setDisplayShowtitleEnabled(false); // actionBar.setIcon(R.drawable.ic_action_search); LayoutInflater inflator = (LayoutInflater) this .getSy@L_673_12@service(Context.LAYOUT_INFLATER_serviCE); View v = inflator.inflate(R.layout.test,null); actionBar.setCustomView(v); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,COUNTRIES); AutoCompleteTextView textView = (AutoCompleteTextView) v .findViewById(R.id.editText1); textView.setAdapter(adapter); } }
的test.xml
<LinearLayout xmlns:android="http://scheR_245_11845@as.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Action Bar:" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> <AutoCompleteTextView android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:imeOptions="actionSearch" android:inputType="textAutoComplete|textAutoCorrect" android:textColor="#FFFFFF" > <requestFocus /> </AutoCompleteTextView> </LinearLayout>
以上是大佬教程为你收集整理的在Android中自动完成文本?全部内容,希望文章能够帮你解决在Android中自动完成文本?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。