簡體   English   中英

從活動傳遞數據以查看尋呼機片段

[英]Pass data from activity to view pager fragment

對不起,英語不好。

我使用改造創建了選項卡布局,並且選項卡名稱或標題沒有問題。 但是,當我嘗試將數據ID傳遞給片段時,出現了問題。

在我的活動中:

     public void onResponse(Response<CategoryResponse> response, Retrofit retrofit) {
            mProgressDialog.hide();
            FragmentKonten deskripsi;
            if(response.body().getStatus().equals("ok"))
            {
                CategoryResponse produkListResponse = response.body();
                for (Category category : produkListResponse.getListProduk())
                {
                    bundle.putInt("category",category.getId());

                    deskripsi=new FragmentKonten();
                    deskripsi.setArguments(bundle);

                    adapter.addFragment(deskripsi,category.getTitle());
                    adapter.notifyDataSetChanged();
                }
            }
            else{
                pesan(getActivity());
            }
        }

在我的片段中:

 bundle = this.getArguments();

    Toast.makeText(getActivity(),String.valueOf(bundle.getInt("category")),Toast.LENGTH_LONG).show();

我想要的結果是:

類別標題和ID:

Diet Sehat = 3

Khas Indonesia = 4

Resep Kue = 7

Resep Macanegara = 9

etc

但是實際結果是:

Diet Sehat = 9

Khas Indonesia = 9

Resep Kue = 9

Resep Macanegara = 9

etc

你有沒有嘗試過:

for (Category category : produkListResponse.getListProduk())
                {
                    Bundle bundle = new Bundle(); //I guess you're missing this
                    bundle.putInt("category",category.getId());

                    deskripsi=new FragmentKonten();
                    deskripsi.setArguments(bundle);

                    adapter.addFragment(deskripsi,category.getTitle());
                    adapter.notifyDataSetChanged();
                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM