I am a newbie to android, I know this question has already been asked but i couldn't get a satisfactory explanation. My doubts are:
I hope the questions is clear, if not please say so in the comments.
I myself was also confused about what was the real purpose of attachToRoot
in inflate
method. After a bit of UI study, I finally got the answer:
parent:
in this case is the widget/layout that is surrounding the view objects that you want to inflate using findViewById().
attachToRoot:
attaches the views to their parent (includes them in the parent hierarchy), so any touch event that the views recieve will also be transfered to parent view. Now it's upto the parent whether it wants to entertain those events or ignore them. if set to false, they are not added as direct children of the parent and the parent doesn't recieve any touch events from the views.
Hope this clears the confusion
The third parameter in the inflate method has a boolean return type.
There is a lot of confusion(Will get to this part soon) when it comes to choosing the value of the parameter.
** It's Simple**
Don't attach the child view to parent "Right Now", Add it later.
Attach the childView to parent "Right Now".
In both cases, the child view will be added to parentView eventually. ** It's just a matter of time.**
If you want to read in more details you can refer ---> this answer
(Because I can not post the duplicate answer here, Happy to help).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With