Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use AsyncLayoutInflater with DataBinding

I currently inflate most of my layouts using the DataBindingUtil.inflate(inflater, layoutId, parent, attachToParent) method.

But I saw that their is an AsyncLayoutInflater since Support Library revision 24 that allow the inflation to occur on a separate thread. I would like to use this mechanism in some part of my app but I don't want to drop the use of databinding for that.

DataBindingUtil doesn't contain any method like inflateAsync(). But is it plan to add a support for that? Or is their a way to combine both the AsyncLayoutInflater and the use of databinding?

I tried to use the AsyncLayoutInflater inside the inflate method of DataBindingUtil but actually AsyncLayoutInflater is not a subclass of the original LayoutInflater.

Thank's for reading!

like image 216
MHogge Avatar asked Mar 27 '18 15:03

MHogge


1 Answers

You can just use DataBindingUtil.bind(view) to bind to the root of the inflated layout.

new AsyncLayoutInflater(this).inflate(R.layout.my_layout, null, new AsyncLayoutInflater.OnInflateFinishedListener() {
    @Override
    public void onInflateFinished(@NonNull View view, int resid, @Nullable ViewGroup parent) {
        MyLayoutBinding binding = DataBindingUtil.bind(view);
    }
});
like image 194
James McCracken Avatar answered Sep 18 '22 20:09

James McCracken