我需要在 MvxFragment 中找到我在 axml 中声明的 View 。在 Activity 中我可以调用 FindViewById<T>(RESOURCE_ID)
在OnCreate
.这在 fragment 中不起作用。
这是它与普通 Android fragment 一起工作的方式:findViewById in Fragment
如何在 MvxFragment
中膨胀 View 不丢失绑定(bind)上下文?
最佳答案
它是这样工作的:
您需要了解 EnsureBindingContextIsSet()
和 BindingInflate()
这两个扩展方法。
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;
}
}
关于c# - 在 MvxFragment 中通过 Id 查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30211488/