I have a method, initializeViews, which encounters an ArrayAdapter constructor undefined error in its last line.
The method is located in F1Fragment, which extends MainFragment. MainFragment is then attached to an Activity.
Can we not give the context of a Fragment in the ArrayAdapter<string> constructor? I am new to Android. Please correct me. Thanks in advance.
private void initializeViews(RelativeLayout contentLayout) {
leaguesListView = ( ListView ) contentLayout.findViewById ( R.id.leaguesListView );
progressLinear = (LinearLayout) contentLayout.findViewById ( R.id.progressLeagues );
values= new String[] { "RedBullRacing", "McLaren", "Lotus",
"ForceIndia", "HRT", "Ferrari" };
adapter= new ArrayAdapter<String>(F1Fragment.this, android.R.layout.simple_list_item_1, android.R.id.text1, values);
}
Change F1Fragment.this to getActivity(). The Fragment is not a Context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With