2
幾乎讓它運行。 所以,我有我的靜態PlaceholderFragment,看起來像這樣:在片段中指定AutoCompleteTextView適配器
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;
}
}
所以我的問題是這樣的一行:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
我得到的錯誤如下:
Cannot resolve constructor 'ArraAdapter(com.g.h.MainActivity.PlaceholderFragment,int,java.lang.String[])'
我確實嘗試在「this」之前放置課程:
MainActivity.this
在評論由NollyĴ給予210
當您執行了'MainActivity.this'時發生了什麼? –
使用getActivity()取代這個 – Inducesmile
getActivity取得了神奇的效果。真棒 – mogren3000