search

Home  >  Q&A  >  body text

java - Implement a button on both sides. Click the button to switch the content in the middle. The middle can be a fragment. How to achieve this effect?

Implement a button on both sides. Click the button to switch the content in the middle. The middle can be a fragment. How to achieve this effect? ​​
I have tried viewpager, but it is not easy to use in the project , please find other solutions.

習慣沉默習慣沉默2742 days ago812

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:35:43

    Why don’t you use a list to save your fragment? Click the left and right buttons to perform the corresponding list.get(position) addition and subtraction operations, and then replace the fragment. Is this enough to meet your needs?

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 13:35:43

    This is very simple.

    To display a fragment, click the button to show it directly, or replace the current fragment

    getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, fragmentA)
                    .commit();

    Button can use RadioGroup to nest RadioButton

    reply
    0
  • Cancelreply