7

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

1 Answer 1

38

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.