-4

I'm attempting to populate a list in a ListView. The Fragment I'm using is a tab in my activity. When I'm trying to create the adapter for the ListView, I encounter an issue. The adapter I've created TaskItemAdapter up to this point was used in an activity in which there were no tabs, so the contractor was:

    public TaskItemAdapter(Context context, List<Task> list) {
    this.itemList = list;
    this.context = context;
    inflater = LayoutInflater.from(this.context);
}

This is the initialization:

list.setAdapter(new TaskItemAdapter(context, itemList));

But when I try this in a Fragment, I encounter an issue, as there is no Context to transfer to the contractor. How can I resolve this?

David Faizulaev
  • 4,651
  • 21
  • 74
  • 124

1 Answers1

4

use getActivity() instead of context in your Fragment:

list.setAdapter(new TaskItemAdapter(getActivity(), itemList));
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150