抱歉英语不好。
我使用改造创建了标签布局,标签名称或标题没有问题。 但是当我试图将数据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
答案 0 :(得分:0)
你试过了吗?
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();
}