So I came across some odd behavior when it comes to the getVIew () method in the fragment class. From the documentation, I expect to get the view created in the onCreateView method, as indicated here http://developer.android.com/reference/android/app/Fragment.html#getView ()
"Get the root view for the fragment layout (the one returned by onCreateView (LayoutInflater, ViewGroup, Bundle)), if provided"
Now I have a view in which there are many children, so I wanted to try and save when I try to findViewById by implementing the ViewHolder class, similar to the usual way that it does in the ListView adapters that I set as the view tag returned from onCreateView.
Odd behavior occurs later when I call the getView method. It appears that the fragment returns the parent of the created view, not the created view, which results in the return of the null tag.
I wrote a small price for the code to print the view (nested children if the view is actually a viewGroup), and this is what I get.
android.widget.ScrollView android.widget.ScrollView@4242dec0 /android.widget.ScrollView
and when I print it later using the getView () method, I get
android.support.v4.app.NoSaveStateFrameLayout android.widget.ScrollView android.widget.ScrollView@4242dec0 /android.widget.ScrollView /android.support.v4.app.NoSaveStateFrameLayout
As you can see, ScrollView is the view that I actually create in the onCreateView method. So why does getView return the parent instead of the view?
source share