Android- Why Is This Happening ("content Not Yet Created" Error)
Solution 1:
The key here is when setAdapter() is being called inside your ListFragment.
In your first example, setAdapter() was being called inside onCreateView() which won't work because the ListFragment checks to ensure there is a list defined in your layouts before allowing the adapter to be set and until onCreateView() returns the view you are creating, there isn't a layout to check. It's a chicken and egg problem.
The reason the second example works is because you aren't actually callnig setAdapter() from within onCreateView(). The adapter isn't set until the button is clicked in your resulting layout.
The basic issue here is that fragments differ from activities in that you can't do the same sorts of things in onCreate() as you are used to doing with your activities, especially when it comes to setting up your adapters.
Solution 2:
Do you extend the Fragment Class or the ListFragment? This is how I used it inside a ListFragment ->
publicclassFooFragmentextendsListFragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Viewroot= inflater.inflate(R.layout.fragment_eventlist, null);
eventAdapter = newEventAdapter(getActivity(), R.layout.list_item_event, events);
setListAdapter(eventAdapter);
return root;
}
}
Edit:
Just modify the variables and types:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Viewroot= inflater.inflate(R.layout.fragment_activitystream, null);
return root;
}
@OverridepublicvoidonCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
states = newArrayList<Status>();
...
YourAdapterasa=newYourAdapter(getActivity(), R.layout.list_item_status, states);
setListAdapter(asa);
Log.i(TAG, "onCreate is done");
}
Post a Comment for "Android- Why Is This Happening ("content Not Yet Created" Error)"