Context type in fragment
I have implemented a FragmentPagerAdapter with 4 tabs and I have
associated a fragment to each of them. One of the views loads a GridView
with images as follows:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.init, container, false);
final GridView grid = (GridView)view.findViewById(R.id.myGrid);
grid.setNumColumns(2);
grid.setAdapter(new ImageAdapter(getActivity()));
return view;
}
The problem is that the method 'new ImageAdapter(context)' receives as a
parameter a variable type Context to load in method 'newImageView
(context)' that it needs this type of variable and passing 'getActivity()'
I have next mistake:
No enclosing instance of type IniSel is accessible. Must qualify the
allocation with an enclosing instance of type IniSel (e.g. x.new A() where
x is an instance of IniSel).
(IniSel is the Class name)
How I can fix?
How do I pass a variable Context type within a class that inherits from
Fragment?
Thanks in advance.
No comments:
Post a Comment