Murat
Murat

Reputation: 445

Cant set list to custom adapter in fragment

I'm trying to create listview with custom adapter, everything fine in activity class. but fragment extended class i can not set list in my custom adapter.print screen

Upvotes: 0

Views: 883

Answers (2)

Jawascript
Jawascript

Reputation: 703

Your problem is in this line

CustomListAdapter customAdapter = new CustomListAdapter(this, list);

More specifically the keyword this is your problem. You are trying to pass this as Context, which works in an Activity, because Activities have Context. However, Fragments do not.

So you must call the parent Activity's Context like so:

CustomListAdapter customAdapter = new CustomListAdapter(getActivity(), list);

Upvotes: 1

Mohammad Rahchamani
Mohammad Rahchamani

Reputation: 5220

you should pass a Context object as first argument of your CustomListAdaptor's constructor but you are passing a Fragment objecy instead. try this :

CustomListAdaptor customListAdaptor = new CustomListAdaptor(getActivity(), list);

Upvotes: 5

Related Questions