SemperAmbroscus
SemperAmbroscus

Reputation: 1388

Fragment compatibility issues:

I am following the tutorial on the android website on how to have a button switch the fragment. Well I am receiving conflict between android.support.v4.app.Fragment and android.app.Fragment. So I tried changing all The fragments on the page to one or the other but it seams that both are needed for the process although this isn't possible.

To elaborate, the first thing it has you do is create a fragment manager like so:

FragmentManager fragmentManager = getFragmentManager();

The problem I have down the line is that this line of code wants the android.support.v4.app.Fragment while the default generated one on a brand new activity is android.app.Fragment. I then tried switching the default generated one over and that gives me a different conflict. It would be helpful if someone could show me or link me to a tutorial where they properly present which fragment class to use.

Upvotes: 0

Views: 72

Answers (2)

Sebastien Bianchi
Sebastien Bianchi

Reputation: 722

If you're using import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; you must use getSupportFragmentManager(); instead of getFragmentManager();.

Source: http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

Upvotes: 2

David
David

Reputation: 850

Just use the v4 for all related fragment actions.

In your case :

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

Upvotes: 1

Related Questions