I've added autoCompleteTextView to my activity.
<AutoCompleteTextView
android:id="@+id/autoCompleteTextViewSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:textColor="@color/zxing_status_text"
app:layout_constraintBottom_toBottomOf="@+id/toolbar2"
app:layout_constraintLeft_toLeftOf="@+id/toolbar2"
app:layout_constraintRight_toRightOf="@+id/toolbar2"
app:layout_constraintTop_toTopOf="@+id/toolbar2" />
Then I've added code to MainActivity.java in onCreate:
String[] arrayData = {
"30714518 Tyre Bycicle 14\"x2.125 ORNATE 518 2000289537714 190 300 2 1",
"30718827 Tyre Bycicle 18\"x1.75 DURO 827 2000289544736 170 350 0 4",
"307275161-1 Tyre Bycicle 27,5\"x2.10 CHAOYANG 5161 2000289537813 400 650 1 3",
"30710590 Tyre Bycicle 10\"x2.0 H-590 CHAOYANG 2000289557941 170 300 0 5",
"30718518 Tyre Bycicle 18\"x2.125 ORNATE 518 2000289537745 220 400 1 9",
"30716518 Tyre Bycicle 16\"x2.125 ORNATE 518 2000289537721 200 350 1 114",
"30718888 Tyre Bycicle 2000289537721 200 350 1 114"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.select_dialog_item, arrayData);
AutoCompleteTextView autoCompleteWidget = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextViewSearch);
autoCompleteWidget.setThreshold(1);
autoCompleteWidget.setAdapter(adapter);
What's going on when I start my app and type text in the autocompleted field:
Why when I type 30714 there no results?
I tried to change the 1st string and every time there no results when I try to find the first phrase of the 1st string.
How is your dataFromFileInList
get created?
If your adapter data is from arrayData
, it should works like the code below.
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view);
final String[] arrayData = {
"30714518 Tyre Bycicle 14\"x2.125 ORNATE 518 2000289537714 190 300 2 1",
"30718827 Tyre Bycicle 18\"x1.75 DURO 827 2000289544736 170 350 0 4",
"307275161-1 Tyre Bycicle 27,5\"x2.10 CHAOYANG 5161 2000289537813 400 650 1 3",
"30710590 Tyre Bycicle 10\"x2.0 H-590 CHAOYANG 2000289557941 170 300 0 5",
"30718518 Tyre Bycicle 18\"x2.125 ORNATE 518 2000289537745 220 400 1 9",
"30716518 Tyre Bycicle 16\"x2.125 ORNATE 518 2000289537721 200 350 1 114",
"30718888 Tyre Bycicle 2000289537721 200 350 1 114"
};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item, Arrays.asList(arrayData));
autoCompleteTextView.setThreshold(1);
autoCompleteTextView.setAdapter(adapter);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.