10 Jun 2014, 19:18
Generic-user-small

Joel Cron (1 post)

So, I struggled with this in Android 4.4 for a while. My XML was correct, my code compiled, but I could not get findViewById() to return anything but null. What I finally figured out is that PlaceHolderFragment.onCreateView() is called after onCreate() for SudokuActivity completes. This means the resources defined in the fragment_soduku.xml file aren’t yet available when you try to set the click listeners in onCreate().

I copied the <LinearLayout/> xml into my activity_soduku.xml file and deleted the created code in onCreate() that adds the PlaceHolderFragment to the FragmentManager. It finally loads correctly. I guess that’s what I get for reading Hello, Android and the Google Android tutorials at the same time.

I hope this helps others struggling with this.

  You must be logged in to comment