I am getting an error at autoCompleteTextView it says setAdapter(T) cannot be applied to (android.widget.ListAdapter)
public class HomeFragmnet extends Fragment {
TextInputLayout textInputLayout;
AutoCompleteTextView autoCompleteTextView;
ListView listView;
ListAdapter listAdapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstancesState){
View v =inflater.inflate(R.layout.fragment_home, null);
textInputLayout = (TextInputLayout) v.findViewById(R.id.menu_dropdown);
autoCompleteTextView = (AutoCompleteTextView) v.findViewById(R.id.drop_items);
String [] items={"Pune", "Mumbai", "Nashik"};
listAdapter = new ArrayAdapter<String>(getActivity() , R.layout.items_list, items );
autoCompleteTextView.setAdapter( listAdapter );
return v;
}
}
CodePudding user response:
According to the docs of AutocompleteTextView
its setAdapter
method takes a <T extends ListAdapter & Filterable>
, meaning the adapter must both extend ListAdapter
and implement Filterable
.
ListAdapter
itself does not implement Filterable
, but some subclasses such as ArrayAdapter
do.