0

i am new in android development, i want to call flipCard() from OnClickListener but i can not, how to call this method? i do not want(actually i can not) change modifier of flipCard to static

this is my codes:

public class Frags extends Fragment {
    private boolean mShowingBack = false;
    CardFrontFragment fr = new CardFrontFragment();
    CardBackFragment bk = new CardBackFragment();
    static View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (!mShowingBack) {
            return fr.onCreateView(inflater, container, savedInstanceState);
        } else {
            return bk.onCreateView(inflater, container, savedInstanceState);
        }
    }

    public static class CardFrontFragment extends Fragment {
        public CardFrontFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            view = inflater.inflate(R.layout.fragment_card_front, container, false);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    /* how to call flipCard() from here? */
                }
            });

            return view;
        }
    }

    public static class CardBackFragment extends Fragment {
        public CardBackFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            view = inflater.inflate(R.layout.fragment_card_back, container, false);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {

                }
            });
            return view;
        }
    }

    public void flipCard() {
        if (mShowingBack) {
            getChildFragmentManager().popBackStack();
            mShowingBack = !true;
            return;
        }
        mShowingBack = true;
        getChildFragmentManager()
                .beginTransaction()
                .setCustomAnimations(
                        R.animator.card_flip_right_in, R.animator.card_flip_right_out,
                        R.animator.card_flip_right_in, R.animator.card_flip_right_out)
                .replace(R.id.container, this.bk)
                .addToBackStack(null)
                .commit();

    }
}
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
arsenal
  • 199
  • 1
  • 1
  • 13
  • I've never had a problem calling public/private class methods from within internal classes. I'm not entirely sure this is your problem, but is there a reason your CardFront/Back fragments are static? – RoraΖ Jul 09 '14 at 17:39
  • when i delete static word :This fragment inner class should be static , you know why? – arsenal Jul 09 '14 at 17:43
  • Wait, nested fragments? Just rip out the Fragments and don't make them static inner classes and you should be good to go. – EpicPandaForce Jul 09 '14 at 17:50
  • This should explain why you shouldn't have inner fragment classes. Just create public classes for each one and you should be fine. http://stackoverflow.com/questions/15571010/fragment-inner-class-should-be-static – RoraΖ Jul 09 '14 at 17:51

0 Answers0