Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}
like image 209
Feona Avatar asked Aug 29 '12 07:08

Feona


1 Answers

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

like image 186
Adam Monos Avatar answered Nov 20 '22 13:11

Adam Monos