我创建了一个包含多个片段的应用
我该如何解决这个问题?
更改片段的代码:
public void ChangeFragment(View view) {
Fragment fragment;
if (view == findViewById(R.id.button_sp)) {
fragment = new SpoilerFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
}
if (view == findViewById(R.id.button_bl)) {
fragment = new BlinkFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
}
if (view == findViewById(R.id.button_br)) {
fragment = new BremslichtFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
}
if (view == findViewById(R.id.button_ru)) {
fragment = new RucklichtFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
}
if (view == findViewById(R.id.button_ruc)) {
fragment = new RuckfahrleuchteFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
}
if (view == findViewById(R.id.button_sz)) {
fragment = new SzenenFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
}
}
以下是我在启用专家模式后刷新或如何转到该片段的方法:
public void refresh() {
Fragment fragment;
fragment = new BlinkFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
}
专家模式功能仅将标志设置为true。 这是binkfragment的一部分:
public class BlinkFragment extends Fragment implements View.OnClickListener { private Switch switch_b1, switch_b2; private DiscreteSeekBar discrete_bl_g, discrete_bl_h; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_blink, container, false); discrete_bl_g = (DiscreteSeekBar) v.findViewById(R.id.discrete_bl_g); discrete_bl_h = (DiscreteSeekBar) v.findViewById(R.id.discrete_bl_h); discrete_bl_g.setEnabled(ledControl.instance.data.expertMode); discrete_bl_h.setEnabled(ledControl.instance.data.expertMode);
ledControl主类 https://docs.google.com/document/d/12gbxRStzLDmC2Q0kj7EJsx3fnHpeQ5sQNhWbTKTjxx8/edit?usp=sharing