Reputation: 663
Almost getting it running. So I have my static PlaceholderFragment that looks like this:
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
// Get a reference to the AutoCompleteTextView in the layout
AutoCompleteTextView textView = (AutoCompleteTextView) rootView.findViewById(R.id.customer);
String[] customers = getResources().getStringArray(R.array.al_customers);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, customers);
textView.setAdapter(adapter);
return rootView;
}
}
So my problem is this row:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
The error I am getting is as follows:
Cannot resolve constructor 'ArraAdapter(com.g.h.MainActivity.PlaceholderFragment,int,java.lang.String[])'
I did try to put a class in front of "this":
MainActivity.this
Upvotes: 3
Views: 3108
Reputation: 11
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) view.findViewById(R.id.autocomplete_type_pres);
autoCompleteTextView.setAdapter(new ArrayAdapter<String>( getActivity(),android.R.layout.simple_dropdown_item_1line, mylist));
Upvotes: 2
Reputation: 663
Answer given by Nolly J in comment:
"use getActivity() to replace this"
And it worked like magic.
Upvotes: 1