【问题标题】:Refreshing Fragment everytime navigational drawer item is clicked每次单击导航抽屉项目时刷新片段
【发布时间】:2016-04-14 18:36:21
【问题描述】:

我有带导航抽屉的 BaseActivity,我使用片段管理器在片段布局中显示/隐藏片段,当单击每个导航抽屉项目时,我想在每次单击导航项目时刷新我的片段我尝试了几件事,例如片段附加/分离但它不起作用,任何人都可以帮助我每次单击导航项时如何刷新我的片段。

【问题讨论】:

  • 你试过view.invalidate();吗?
  • 要刷新什么内容?
  • 你可以试试替换片段??

标签: java android android-fragments


【解决方案1】:

我认为您可以通过此导航抽屉回调广播更新操作:

public boolean onNavigationItemSelected(MenuItem item) {
        Intent intent = new Intent(ACTION_UPDATE); // Just string constant
        getActivity().sendBroadcast(intent);
        return false;
}

然后在你的片段中注册接收器:

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    getActivity().registerReceiver(updateReceiver, new IntentFilter(Consts.ACTION_KEYPAD_DISARMED));
}

@Override
public void onDetach() {
    super.onDetach();
    getActivity().unregisterReceiver(updateReceiver);
}

private BroadcastReceiver updateReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Write here code of fragment updating
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多