片段中的上下文类型

时间:2013-09-30 15:04:31

标签: android fragment android-context fragmentpageradapter

我已经实现了一个带有4个标签的FragmentPagerAdapter,并且我已经为每个标签关联了一个片段。其中一个视图加载GridView图像,如下所示:

@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;
}

问题是方法new ImageAdapter(context)作为参数接收变量类型Context以在方法newImageView (context)中加载它需要这种类型的变量并传递getActivity()我有下一个错误:

  

无法访问IniSel类型的封闭实例。必须使用IniSel类型的封闭实例限定分配(例如x.new A(),其中x是IniSel的实例)。

(IniSel是班级名称)

我如何解决?

如何在继承自Fragment的类中传递变量Context类型?

0 个答案:

没有答案