listView不会立即更新

时间:2014-07-14 14:11:30

标签: android listview android-fragments

我有一个Activity,其中包含2个动态片段(一次只显示其中一个片段)。 其中一个片段(HasExploitsFragment)包含一个listView。

当活动恢复时(已调用恢复功能),(在添加到列表中的对象之后) 列表(在HasExploitsFragment片段中)未更新..

恢复功能是:

@Override
    protected void onResume() {
        super.onResume();
        if (exploitTitleAndDescription.get(HasGroupsFragment.groupChosen)
                .size() == 0) {
            // Hide the fragment
            FragmentManager fm = getFragmentManager();
            fm.beginTransaction()
                    .setCustomAnimations(android.R.animator.fade_in,
                            android.R.animator.fade_out)
                    .hide(hasExploitsFragment).commit();
            addDynamicNoExploitsFragment();
        } else {
            //We enter this section, but despite that, the update is not shown immediately :(
            FragmentManager fm = getFragmentManager();
            fm.beginTransaction()
                    .setCustomAnimations(android.R.animator.fade_in,
                            android.R.animator.fade_out)
                    .hide(noExploitsFragment).commit();
            addDynamicHasExploitsFragment();    
        }
    }

和addDynamicHasExploitsFragment()如下:

private void addDynamicHasExploitsFragment() {
        hasExploitsFragment = new HasExploitsFragment();
        getFragmentManager().beginTransaction()
                .add(R.id.exploits_main_menu, hasExploitsFragment).commit();
    }

当我退出活动并再次输入时,列表会更新。 如何立即执行更新(在上面的恢复功能详细信息中)?

1 个答案:

答案 0 :(得分:0)

您需要致电notifyDataSetChanged()来更新列表视图。