如何从Android中的Fragment调用ArrayAdapter构造函数

我正在尝试将两列ListView添加到我的Android应用程序中。 当我创建项目时,我选择了Fragment选项,它通过向左和向右滑动创建了漂亮的导航。 所以我的MainActivity扩展了FragmentActivity

我的问题是当我试图将AddayAdapter添加到ListView时,ArrayAdapter的construstor寻找上下文对象,我不知道要传递它。

这是我得到错误的代码

 StableArrayAdapter adapter = new StableArrayAdapter(this, R.layout.row , list); listview.setAdapter(adapter); 

当我传递“this”时,它传递FragmentActivity,因为活动扩展了FragmentActivity。 但构造函数需要一个“Context”对象。

它给出了此错误消息

 "The constructor MainActivity.StableArrayAdapter(MainActivity.DummySectionFragment, int, ArrayList) is undefined" 

我怎样才能传递Context对象?

您正在片段内设置适配器。 使用

 StableArrayAdapter adapter = new StableArrayAdapter(this.getActivity(), R.layout.row , list); 
 StableArrayAdapter adapter = new StableArrayAdapter(getContext(), R.layout.row , list); listview.setAdapter(adapter); 

你试过从片段中传递这样的东西吗? 尝试getContext()getApplicationContext()