我是xamarin的新手,我正在尝试创建一个list in a fragment
并将其传递给我的主要活动。但是当我拨打我的适配器时,我得到null
。
这是我片段中的onCreateView。
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.TechsJob_List, container, false);
var JobsList = view.FindViewById(Resource.Id.TechListRow_ListView);
var JobsListAdapter = new TechsJob_Adapter(this);
JobsList.Adapter = JobsListAdapter; //NullRefernce
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
base.OnCreateView(inflater, container, savedInstanceState);
return view;
}
答案 0 :(得分:1)
你的适配器需要上下文而不是fragement
var JobsListAdapter = new TechsJob_Adapter(this);
在此你传递的是你应该将活动上下文传递给它的fragement。它应该是这样的
var JobsListAdapter = new TechsJob_Adapter(this.Activity);
希望这会对你有所帮助。
答案 1 :(得分:0)
var adapter = new jobsadapter(Activity);