0

I have a fragment layout and left sidemenu (drawer menu). It works fine, but I want to make my fragment show different layouts like a wizard. I wasn't able to do that.

public class TheWizard extends Fragment{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.wizardstep1, container, false);

This way, I'm able to show first layout, now when I try to do:

Button button= (Button) v.findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            View vstep2 = inflater.inflate(R.layout.wizardstep2, null, false);

It doesn't work. I want my fragment to show multiple layout and each layout will have different checkboxes and textboxes. It's a step-by-step wizard, but I want it to be fragment and I want to keep left drawer menu staying there whole time. Any ideas? I even tried to set inflate and container variables as public variables, so I can use in onClick function, but still no luck.

1 Answers1

0

There is a problem when you change the view of the fragment... when you change it the current button you are pressing to inflate a view will be null because you changed the view which that button resides..

Instead of changing the view of the fragment each time..

What you can do is that you can add a fragment inside that fragment...

Click here for more info on adding a fragment inside a fragment..

Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
  • any other way? Because I have to do it like a wizard, so I'm going to create, delete, create, delete new and new layouts... –  May 03 '14 at 00:23
  • I just saw right now that nested fragments only supported in 4.2, I'm using API 8, do you think it will work in API 8? http://stackoverflow.com/questions/6672066/fragment-inside-fragment –  May 03 '14 at 01:00