我正在调用Web服务时重新启动视图页导航中的片段,但无法更新片段中传递的参数。第一次通过的东西仍然是一样的。
验证码:
@Override
protected void onPostExecute(String response) {
state = mOverviewData.getState();
setupViewPager(mViewPager, isSuccess);
}
private void setupViewPager(ViewPager viewPager, boolean isSuccess)
{
Adapter adapter = new Adapter(getSupportFragmentManager());
if(isSuccess){
fab.setVisibility(View.VISIBLE);
Fragment chartFrag = new OverviewChartFrag();
Bundle arg = new Bundle();
arg.putString("state_name", state);
arg.putSerializable("total_blocks", mOverviewData.getTotalBlock());
arg.putSerializable("block_status_obj", mOverviewData.getBlockStatusData());
arg.putParcelableArrayList("mineral_wise_list", (ArrayList<? extends Parcelable>) mineralList);
chartFrag.setArguments(arg);
Fragment blocksFrag = new OverviewDataFrag();
arg = new Bundle();
arg.putString("state_name", state);
arg.putParcelableArrayList("public_data_list", (ArrayList<? extends Parcelable>) mOverviewData.getPublicTableData());
blocksFrag.setArguments(arg);
adapter.addFragment(chartFrag, getResources().getString(R.string.chart_tab));
adapter.addFragment(blocksFrag, getResources().getString(R.string.data_tab));
viewPager.setAdapter(adapter);
} else {
fab.setVisibility(View.GONE);
Fragment noNetFrag = new ServerErrorFrag();
adapter.addFragment(noNetFrag, getResources().getString(R.string.error));
viewPager.setAdapter(adapter);
}
}
2条答案
按热度按时间shstlldc1#
您不必在
onPostExecute
内部调用setupViewPager
。使用下面的代码来获取以前添加的Fragment
的引用并完成您的工作。编码愉快。
nhhxz33t2#
你可以这样使用: