At the very beginning of my app I load up some Fragments in tabs. Here is one that I load:
WishlistFragment wishlistfragment = new WishlistFragment();
Once the Fragment has been loaded and displayed, I will be calling this from other Fragments:
wishlistfragment.adapter.notifyDataSetChanged();
The problem is, if I call this BEFORE the wishlistfragment is ever created/displayed, I get the following exception:
java.lang.IllegalStateException: Content view not yet created.
Is there a way, programmatically, to determine if a view has been created yet?
I don't know of a built-in way, but you could devise your own by making a method to handle the notification and overriding onCreateView
in your WishlistFragment
. Something like this might work:
public class WishlistFragment extends ListFragment {
private boolean _viewExists = false;
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle bundle )
{
_viewExists = true
return super.onCreateView( inflater, container, bundle );
}
public void notifyChange()
{
if ( _viewExists )
getListAdapter().notifyDataSetChanged();
}
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