我需要在MvxFragment中找到我在axml中声明的视图。在活动中,我可以在OnCreate
中致电MvxFragment
。这不适用于片段。
这就是普通Android片段的工作原理:findViewById in Fragment
如何在不丢失绑定上下文的情况下对EnsureBindingContextIsSet()
中的视图进行充气?
答案 0 :(得分:5)
这是它的工作原理:
您需要了解两种扩展方法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;
}
}
。
private class AlbumArtTask extends AsyncTask<String, Bitmap, Uri> {
ImageView mImageView;
Context mContext;
public AlbumArtTask(Context context,ImageView imageView){
this.mImageView=imageView;
this.mContext=context;
}
@Override
protected Uri doInBackground(String... strings) {
final String id = strings[0];
// This part is what I'm asking for, basically to be able to make an Async
// lookup of the url that will later be used by Picasso
final Uri uri = getAlbumArtUriFromTrackId(id);
// Creating the Bitmap and return it to be used in an ImageView
// This part is handled by Picasso
return uri;
}
@Override
protected void onPostExecute(Uri uri) {
// You have to pass imageview in constructor.
// load image into ImageView
Picasso.with(mContext).load(uri)/* And load it here*/.into(mImageView);
}
}