0

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
KryNaC
  • 379
  • 4
  • 21

0 Answers0