C# MvxFragment中的FindViewById
我需要在MvxFragment中找到我在axml中声明的视图。在活动中,我可以在C# MvxFragment中的FindViewById,c#,android,android-fragments,mvvmcross,C#,Android,Android Fragments,Mvvmcross,我需要在MvxFragment中找到我在axml中声明的视图。在活动中,我可以在OnCreate中调用FindViewById(资源ID)。这在片段中不起作用 这是它如何处理普通Android片段的: 如何在不丢失绑定上下文的情况下在MvxFragment中膨胀视图?它就是这样工作的: 您需要了解两种扩展方法EnsureBindingContextIsSet()和BindingInflate() 公共类MyFragment:MvxFragment { CreateView上的公共覆盖视图(Lay
OnCreate
中调用FindViewById(资源ID)
。这在片段中不起作用
这是它如何处理普通Android片段的:
如何在不丢失绑定上下文的情况下在MvxFragment
中膨胀视图?它就是这样工作的:
您需要了解两种扩展方法EnsureBindingContextIsSet()
和BindingInflate()
公共类MyFragment:MvxFragment
{
CreateView上的公共覆盖视图(LayoutInflater充气机、ViewGroup容器、Android.OS.Bundle savedInstanceState)
{
这将确保绑定上下文集(savedInstanceState);
var view=this.BindingInflate(Resource.Layout.YOUR_视图,container,false);
var searchField=view.findviewbyd(Resource.Id.Resource\u Id);
返回视图;
}
}
public class MyFragment : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState)
{
this.EnsureBindingContextIsSet(savedInstanceState);
var view = this.BindingInflate(Resource.Layout.YOUR_VIEW, container, false);
var searchField = view.FindViewById<T>(Resource.Id.RESOURCE_ID);
return view;
}
}