Is there any way to determine in Android if a representation of the activity content has been created / displayed?

At the very beginning of my application, I load some snippets in tabs. Here is what I download:

WishlistFragment wishlistfragment = new WishlistFragment(); 

Once the Fragment has been loaded and displayed, I will call this from other fragments:

 wishlistfragment.adapter.notifyDataSetChanged(); 

The problem is that if I name it before the wish list is created / displayed, I get the following exception:

java.lang.IllegalStateException: Content view has not yet been created.

Is there a way, programmatically, to determine if a view has yet been created?

+4
source share
1 answer

I don’t know the built-in way, but you could develop your own by creating a method to handle notifications and override onCreateView in WishlistFragment . Maybe something like this:

 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(); } 
+9
source

Source: https://habr.com/ru/post/1443751/


All Articles