Reputation: 445
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.
Upvotes: 0
Views: 883
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
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