I am trying to get some LinearLayouts
in my onCreateView
but my App is crashing with the following message:
23430-23430/? W/System.e
You're calling getView()
too early - it will only return the view you return yourself from onCreateView()
.
Inside onCreateView()
use the recently inflated rootView
instead of getView()
.
The same NullPointerException
caused while I'm trying to make a component extends view, it may due to the using of LayoutInflater
View view = LayoutInflater.from(context).inflate(R.layout.layout_index_bar, null);
container = (LinearLayout) view.findViewById(R.id.indexContainer);
Change to
card01 = (LinearLayout) rootView.findViewById(R.id.card01);
card02 = (LinearLayout) rootView.findViewById(R.id.card02);
card03 = (LinearLayout) rootView.findViewById(R.id.card03);
card04 = (LinearLayout) rootView.findViewById(R.id.card04);
card05 = (LinearLayout) rootView.findViewById(R.id.card05);
card06 = (LinearLayout) rootView.findViewById(R.id.card06);
You inflate a layout. the views belong to the inflated layout. So use the view object to initialize views in onCreateView
Fragment is hosted by a Acitvity
You can use getView
in onActivityCreated
and initialize views
Initialize your TextView's also in onCreateView
. Since Asynctask is a inner class you can update ui there
Declare
RobotoTextView date_widget2;
as instance variable
Then in onCreateView
date_widget2= (RobotoTextView) rootView.findViewById(R.id.date02);