Reputation: 335
I know this is common to ask but,I tried most resources on the internet and it doesn't work for me, Can anyone how can I achieve this problem?
When I setOntext on my AutoCompleteTextView
The list did not display, When I tried setting the Male
value of AutoCompleteTextView
the Female
did not show only the Male
value shown.
Myjavafile
spinSex = findViewById(R.id.spinnerSex);
String[] Sex = new String[]{"MALE", "FEMALE"};
ArrayAdapter<String> adapterSex = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_item, Sex);
adapterSex.setDropDownViewResource(simple_spinner_dropdown_item);
spinSex.setAdapter(adapterSex);
spinSex.postDelayed(new Runnable() {
@Override
public void run() {
spinSex.setText("MALE");
spinSex.showDropDown();
}
}, 10);
Xml
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/spinnerSex"
android:layout_width= "match_parent"
android:hint="Sex"
android:layout_height="wrap_content"
/>
Updated : I tried this but when I use spinSex.setSelection(spinnerSex);
the error says
java.lang.IndexOutOfBoundsException: setSpan (1 ... 1) ends beyond length 0
Mainactivity.java
String gender ="FEMALE";
new android.os.Handler(Looper.getMainLooper()).postDelayed(
new Runnable() {
public void run() {
adapterSex = (ArrayAdapter) spinSex.getAdapter();
int spinnerSex = adapterSex.getPosition(gender);
spinSex.setSelection(spinnerSex);
}
},
500);
Upvotes: 0
Views: 511
Reputation: 21
Can use this and will work
autoCompleteTextView.setText("what ever you want to show", false)
Upvotes: 1