-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TextInputLayout] [Exposed Dropdown Menu] Set a default selection #1007
Comments
Hi, since the menu uses an So you'd do something like: |
note that this won't survive configuration changes. after a configuration change the item is selected again, but with filtering. items not matching the filter aren't visible anymore. |
@wondering639 Anyway to the make filter visible on configuration change ? I am facing similar issue when I go back to the fragments with navigation components, the filter options are not visible anymore. |
@blacpythoz I solved (workaround) it by creating a non filtering adapter as described in this article: https://medium.com/@rmirabelle/there-is-no-material-design-spinner-for-android-3261b7c77da8 |
@wondering639 is right. setting filtering to false doesn't survive configuration change. I doubt that this is intended behavior. |
Ref: #1464 |
You can use
The |
@gabrielemariotti Thank you, but - without testing it - shouldn't it be |
@wondering639 I try to explain better. To select a default value you have to use: After a rotation or a configuration change the value is still visible but with filtering. Items not matching the filter aren't visible anymore. It happens because the
In this way the |
got it, thanks 👍 |
I have a same bug when i back via navigation component on my fragment where i allready select some item in dropdown |
FIX: All the values will be visible after the device rotation and also the selected value will be displayed. public class TextInputDropDownMenu extends AppCompatAutoCompleteTextView {
public TextInputDropDownMenu(@NonNull Context context) {
super(context);
}
public TextInputDropDownMenu(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public TextInputDropDownMenu(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
{
setInputType(InputType.TYPE_NULL);
}
@Override
public boolean getFreezesText() {
return false;
}
@Override
public Parcelable onSaveInstanceState() {
Parcelable parcelable = super.onSaveInstanceState();
if (TextUtils.isEmpty(getText())) {
return parcelable;
}
CustomSavedState customSavedState = new CustomSavedState(parcelable);
customSavedState.text = getText().toString();
return customSavedState;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
if (!(state instanceof CustomSavedState)) {
super.onRestoreInstanceState(state);
return;
}
CustomSavedState customSavedState = (CustomSavedState) state;
setText(customSavedState.text, false);
super.onRestoreInstanceState(customSavedState.getSuperState());
}
private static final class CustomSavedState extends BaseSavedState {
private String text;
public CustomSavedState(Parcelable superState) {
super(superState);
}
public CustomSavedState(Parcel source) {
super(source);
text = source.readString();
}
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeString(text);
}
private static final Creator<CustomSavedState> CREATOR = new Creator<CustomSavedState>() {
@Override
public CustomSavedState createFromParcel(Parcel source) {
return new CustomSavedState(source);
}
@Override
public CustomSavedState[] newArray(int size) {
return new CustomSavedState[size];
}
};
}
} |
@ar-arvind
|
Did anyone manage to get a fix for this? |
We are working with the Framework and Androidx team to figure out a good solution of this. (List gets filtered after configuration change.) The tracking issue is here: #1464 |
Has there been a fix for this?
I appreciate the fast response. My problem was that the filtering got triggered even if I set it to false. In other words, the text was there on application startup, but there was no way to change it again (I didn't have similar values). Using |
Can you provide more details? Is your issue different from the one after configuration change? |
I'm not sure what you mean by "configuration change" but I was trying to set a default value for my AutoCompleteTextView. The following was not working:
The behavior I got: The text is set properly, but if I click again on the DropDownMenu, it doesn't open. I'm guessing because the filter was ON although I'm explicitly setting it to false as you can see. Doing this:
Fixed the problem. |
I meant after the view is recreated by the framework. Are you setting a default value right after the view is created/inflated? |
I haven't tried that actually. And to answer your question, yes, that's what I'm doing. Is that the wrong way to go by it? |
I think that might be a bug on our end. I need to check. : ) |
Hi @Imadlekal - I cannot reproduce what you said. Can you provide a minimal repro app so we can debug? Or at least more detailed code snippet regarding how you inflate and set up your AutoCompleteTextView. |
I'll close this issue for now due to no further info available. Please feel free to reopen it with a repro. |
Record_2022-09-26-15-28-59.mp4To solve the list filtering issue after a configuration change I set
when instantiating the drop down menu full code:
|
Description: I am going to select default selection programmatically but its not working.
but none of them working.
Source code:
Material Library version: 1.2.0-alpha04
Device: All
The text was updated successfully, but these errors were encountered: