I have two different TextInputLayouts both of which have an AutoCompleteTextView inside them to show a list of user selectable options. The second AutoCompleteTextView changes according to the choices of the first. Everything works perfectly, the adapter updates and everything. The problem is that if I change the choice in the first AutoCompleteTextView, the choice made previously in the second AutoCompleteTextView remains. How can I update the selected item in the second AutoCompleteTextView?
I've tried a lot of methods, clears, setSelection, etc but none work, the only thing that makes it change is setText()
but it just changes the aesthetics! the actual value does not change.
This is the where I handle the AutoCompleteTextViews:
String[] items_type_add_1 = {"Film", "Serie", "Anime", "Giochi"};
String[] items_time_add_1 = {"Important", "General", "Future", "Seen"};
ArrayList<String> items_type_add = new ArrayList<String>(Arrays.asList(items_type_add_1));
ArrayList<String> items_time_add = new ArrayList<String>(Arrays.asList(items_time_add_1));
AutoCompleteTextView element_dropdown_add_type, element_dropdown_add_time;
ArrayAdapter<String> adapter_items_type, adapter_items_time;
adapter_items_type = new ArrayAdapter<String>(AddActivity.this, R.layout.list_item, items_type_add);
adapter_items_time = new ArrayAdapter<String>(AddActivity.this, R.layout.list_item, items_time_add);
element_dropdown_add_type.setAdapter(adapter_items_type);
element_dropdown_add_time.setAdapter(adapter_items_time);
element_dropdown_add_type.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
item_type = adapterView.getItemAtPosition(i).toString();
System.out.println("Item: " + item_type);
textinputlayout_autocomplete_type.setErrorEnabled(false);
switch (item_type) {
case "Film":
textinputlayout_autocomplete_time.setVisibility(View.VISIBLE);
items_time_add = new ArrayList<String>(Arrays.asList("Normal", "Future", "Seen"));
adapter_items_time.clear();
adapter_items_time.addAll(items_time_add);
adapter_items_time.notifyDataSetChanged();
break;
case "Serie":
textinputlayout_autocomplete_time.setVisibility(View.VISIBLE);
items_time_add = new ArrayList<String>(Arrays.asList("Normal", "Future", "Seen"));
adapter_items_time.clear();
adapter_items_time.addAll(items_time_add);
adapter_items_time.notifyDataSetChanged();
break;
case "Anime":
textinputlayout_autocomplete_time.setVisibility(View.VISIBLE);
items_time_add = new ArrayList<String>(Arrays.asList("Important", "General", "Future", "Seen"));
adapter_items_time.clear();
adapter_items_time.addAll(items_time_add);
adapter_items_time.notifyDataSetChanged();
break;
case "Giochi":
textinputlayout_autocomplete_time.setVisibility(View.VISIBLE);
items_time_add = new ArrayList<String>(Arrays.asList("Normal", "Future", "Seen"));
adapter_items_time.clear();
adapter_items_time.addAll(items_time_add);
adapter_items_time.notifyDataSetChanged();
break;
}
}
});
element_dropdown_add_time.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
item_time = adapterView.getItemAtPosition(i).toString();
System.out.println("Item: " + item_time);
textinputlayout_autocomplete_time.setErrorEnabled(false);
}
});