1. 程式人生 > >Activity下使用Viewpager + Fragment; 判斷fragment的顯示情況

Activity下使用Viewpager + Fragment; 判斷fragment的顯示情況

@Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser && isResumed()) {
            Log.d("CXL", "setUserVisibleHint: 1111" + type);
            onResume();
            Log.d("CXL", "setUserVisibleHint: 2222" + type);
        } else if (!isVisibleToUser) {
            onPause();
            Log.d("CXL", "setUserVisibleHint: unVisible" + type);
        }

//        if (getUserVisibleHint()) {
////            onVisible();
//            Log.d("CXL", "setUserVisibleHint: true" + type);
//        } else {
////            onInvisible();
//            Log.d("CXL", "setUserVisibleHint: false" + type);
//        }
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d("CXL", "onResume: type" + type);
        if (getUserVisibleHint()) {
            Log.d("CXL", "onResume: " + type);
            DeliveryListActivity.POST_STATE = type;
        }
    }

Fragment:

Log資訊: