当我在Android中将输入类型作为数字时,自动完成不起作用

sg2wtvxw  于 2023-04-10  发布在  Android
关注(0)|答案(3)|浏览(110)

在我的应用程序中,我使用下面的代码创建了自动完成字段

sugarVariety =  (AutoCompleteTextView)findViewById(R.id.autocomplete_sugarVariety);          
     String[] VARIETY = new String[]{ "118", "119",  "120", "121", "269",    "270",   "271",   "272",  "273",   "346",  "347",   "348", "349",    "350","351",   "352",   "353",    "354",   "355",  "356",  "357", "358",
                "359",  "360", "361", "345", "117",    "266",    "362",    "363",   "364",   "365",   "366",   "367",   "368",  "369",   "370",   "371",  "372",  "373",   "374",   "375",  "376",  "377",
                "378",    "379",    "380",   "239",    "240",   "241",   "242",   "114",  "230", "231",  "101",   "102",  "103", "104",  "108", "111",  "112",  "201",  "202",  "204",  "206",   "207",
                 "208",    "210",   "217",   "218",   "220",  "221",   "226",   "227",  "250", "301",  "302","113", "228",  "0", "246", "999", "205",   "251", "243","268","329", "115", "116", "274"};
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, VARIETY);
     sugarVariety.setAdapter(adapter);

在我的布局中我定义了autocomplete textview

<AutoCompleteTextView android:id="@+id/autocomplete_sugarVariety"
    android:layout_width="wrap_content" android:inputType="number"
    android:layout_height="42px"
    android:layout_marginLeft="5dp"/>

问题是,如果我给予**inputType=“number”**我没有得到数组的数字的AutoComplete列表,如果我删除它,那么只有我得到,但在我的情况下,我想只显示数字键盘,我也需要自动完成可以任何一个告诉我如何才能得到这个...

h6my8fg2

h6my8fg21#

盖伊,你在做一些奇怪的事情。
在你的例子中,你可以把所有的都转换成字符串。如果需要的话,你可以在后面得到数字,你可以再转换成INTLONG。(JUMP rs)

omhiaaxx

omhiaaxx2#

你在这里做的是将String数组设置为输入类型为numberAutoCompleteTextView
因此,通过将ArrayList<String>更改为ArrayAdapter<Integer>将解决此问题。

sugarVariety =  (AutoCompleteTextView)findViewById(R.id.autocomplete_sugarVariety);          
Integer[] VARIETY = new Integer[]{ 118, 119, 120, 121, 269, 270};
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,
                android.R.layout.simple_dropdown_item_1line, VARIETY);
sugarVariety.setAdapter(adapter);

希望能帮上忙。

4si2a6ki

4si2a6ki3#

将filterOptions属性添加到autoComplete组件

<Autocomplete
filterOptions={(options) => options}

相关问题