第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

活動最小化然后恢復后視圖再次可見

活動最小化然后恢復后視圖再次可見

慕妹3242003 2023-08-04 09:59:38
我的應用程序中出現(xiàn)了這個奇怪的事情。我有一個AppCompatActivity,ViewPager里面有兩個片段。我已添加LottieAnimationView到這兩個片段中。在FragmentA我使用從服務器獲取數(shù)據(jù)Retrofit時,它隱藏了LottieAnimationView. 在FragmentB(僅用于檢查問題所在)中,我只是用來Handler隱藏LottieAnimationView3 秒后的內容?,F(xiàn)在,每當我最小化應用程序,然后再次打開它時,我都會看到LottieAnimationView我setVisibility(View.GONE)只在FragmentA. 在 中,當我最小化并再次打開應用程序(按預期工作)后,F(xiàn)ragmentB我看不到視圖。setVisibility(View.GONE)這是我在 中看到的圖像FragmentA。處于LottieAnimationView暫停狀態(tài)。這是我的代碼FragmentA。public class FragmentA extends Fragment {    private AdapterEventStore mAdapter;    private List<Item> mStore;    private final String hostName = "https://xxx.xxx.xxx";    private View view;    private Context context;    private LottieAnimationView lottieAnimationView;    @Nullable    @Override    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {        view = inflater.inflate(R.layout.fragment_a, container, false);        context = view.getContext();        lottieAnimationView = view.findViewById(R.id.ais_lav_loading);        lottieAnimationView.setVisibility(View.VISIBLE);        initRecyclerView();        return view;    }    private void initRecyclerView() {        RecyclerView store = view.findViewById(R.id.ais_rv_event_store);        store.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));        mStore = new ArrayList<>();        mAdapter = new AdapterEventStore(context, mStore);        store.setAdapter(mAdapter);        fetchDataFromServer();    }
查看完整描述

2 回答

?
手掌心

TA貢獻1942條經(jīng)驗 獲得超3個贊

問題是,當您從背景中獲取時, 會onResume被調用,因此您需要添加行來隱藏視圖onResume,而不是onCreateView。


查看完整回答
反對 回復 2023-08-04
?
波斯汪

TA貢獻1811條經(jīng)驗 獲得超4個贊

從 onCrete 中刪除這一行并將其添加到 fetchDataFromServer() 方法中,如下所示。


    public class FragmentA extends Fragment {


    private AdapterEventStore mAdapter;

    private List<Item> mStore;

    private final String hostName = "https://xxx.xxx.xxx";

    private View view;

    private Context context;

    private LottieAnimationView lottieAnimationView;


    @Nullable

    @Override

    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragment_a, container, false);

        context = view.getContext();

        lottieAnimationView = view.findViewById(R.id.ais_lav_loading);

        lottieAnimationView.setVisibility(View.VISIBLE);

        initRecyclerView();

        return view;

    }



    private void initRecyclerView() {

        RecyclerView store = view.findViewById(R.id.ais_rv_event_store);

        store.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));

        mStore = new ArrayList<>();

        mAdapter = new AdapterEventStore(context, mStore);

        store.setAdapter(mAdapter);

        fetchDataFromServer();

    }


    private void fetchDataFromServer() {

        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();

        logging.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        httpClient.addInterceptor(logging);


        final Retrofit retrofit = new Retrofit.Builder()

                .client(httpClient.build())

                .addConverterFactory(GsonConverterFactory.create())

                .baseUrl(hostName)

                .build();

        APIGetItem itemShop = retrofit.create(APIGetItem.class);




        Call<ModelEventExclusive> call = itemShop.getEventStore(hostName);

        call.enqueue(new Callback<ModelEventExclusive>() {

            @Override

            public void onResponse(Call<ModelEventExclusive> call, Response<ModelEventExclusive> response) {

                Log.e("Response: ", response.body().getItems().get(0).getItemName());

                mEventStore.addAll(response.body().getItems());

                mAdapter.notifyDataSetChanged();

                hideLottieAnimation();

            }


            @Override

            public void onFailure(Call<ModelEventExclusive> call, Throwable t) {

                hideLottieAnimation();

                Toast.makeText(context, "Error:"+t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();

                Log.e("Error occurred: ", t.getMessage());

            }

        });

    }


    private void hideLottieAnimation(){

        lottieAnimationView.cancelAnimation();

        lottieAnimationView.setVisibility(View.GONE);

    }

  @Override

    public void onResume() {

        super.onResume();

        lottieAnimationView.setVisibility(View.GONE);

    }

}



查看完整回答
反對 回復 2023-08-04
  • 2 回答
  • 0 關注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號