Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday, 27 September 2017

Fragment Visible or not

Hello guys,


public class HomeFragment extends Fragment
{
private boolean isVisible;

private boolean isStarted;


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_home, container, false);

    
    return view;
}


@Override
public void onStart() {
    super.onStart();
    isStarted = true;
    if (isVisible)
    {
        // Do something
    }
}

@Override
public void onStop() {
    super.onStop();
    isStarted = false;
}

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    isVisible = isVisibleToUser;
    if (isVisible && isStarted)
    {
        // Do something
    }
}

}


Thank you