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 .getSystemService(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://schemas.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中自动完成文本?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)