如何在Fragment替换上保存动态创建的视图?

时间:2016-04-13 15:23:28

标签: android android-fragments

我有一个片段用作表单,我动态使用方法EditText上的CheckboxonCreateView视图填充它。我希望能够保存他们的状态是否有另一个片段在那个之上:

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragment)
        .addToBackStack(fragment.getTagText())
        .commit();

当该片段弹出堆栈时,擦除这些子视图onBackPressed。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

保存您的状态Bandle

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
} 

Bandle恢复:

public void onCreateView(ViewGroup container, Bundle savedInstanceState)

public void onViewCreated(View view, @Nullable Bundle savedInstanceState)

public void onCreate(@Nullable Bundle savedInstanceState)