ViewBinding manipulate view after inflating

SamzSakerz :

I have an instance where I used to pass my View onto a new method to manipulate a couple of things. here I will provide an example. So Basically I am using a RecyclerView and I am inflating the view when the recylerview creates the view

So now I have the inflated View object now I just pass it to my method to manipulate it.

manipulateView(view) manipulateView sets up the color and attributes for the view children

and that used to work and everything. but now I am moving onto ViewBinding

now I have a ViewStub for where I need to inflate my customView

as follows here is the code

ViewDataBinding viewDataBinding = DataBindingUtil.inflate(layoutInflater, getLayoutResource(), viewGroup, false);
ViewStub viewStub = (ViewStub) viewDataBinding.getRoot().findViewById(R.id.stub);

and then I set the layout for the viewStub here

viewStub.setLayoutResource(getLayoutResource());

now setLayoutResource expects an int value with the id of the layout now my question is how can I call manipulateView on getLayoutResource() should I just pass the viewStub and then call viewStub.getRootView() and Manipulate that view?

It would be the best if I was able to manipulate the ViewDataBinding object it self, Should I just manipulate ViewDataBinding::getRoot?

AdamMc331 :

The view that gets inflated by calling layoutInflater.inflate(...) is the same view you would get from viewDataBinding.getRoot(). From the docs, root "returns the outermost view".

So, if that's what you want to manipulate, I would just call manipulateView(viewDataBinding.root).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=82862&siteId=1