Feona
Feona

Reputation: 295

The constructor ArrayAdapter<string> is undefined

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);
}

Upvotes: 7

Views: 13027

Answers (1)

Adam Monos
Adam Monos

Reputation: 4297

Change F1Fragment.this to getActivity(). The Fragment is not a Context.

Upvotes: 38

Related Questions