AndreaF
AndreaF

Reputation: 12375

FragmentTransaction is not applicable for the argument error, if I try to use my custom Fragment

I need to use a fragment container to show various different fragments, so I'm tring to use FragmentManager and FragmentTransaction but If I try to use the following code Eclipse give me the error FragmentTransaction is not applicable for the argument PieFragment in transaction.add(...) line

FragmentTransaction transaction = manager.beginTransaction();
            transaction.add(R.id.fragmentcontainer1, new PieFragment());
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            transaction.commit();
            break;

My custom Fragment is this

public class PieFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        final View v = inflater.inflate(R.layout.fragment_piegraph, container,
                false);
        PieGraph pg = (PieGraph) v.findViewById(R.id.piegraph);
        ...

        pg.setOnSliceClickedListener(new OnSliceClickedListener() {

            @Override
            public void onClick(int index) {

            }

        });

        return v;
    }

    public void updateDisplay() {
        // TODO Auto-generated method stub

    }
}

The Fragment layout

<com.mypackage.graphlibrary.PieGraph
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:id="@+id/piegraph"/>

How could I solve this problem?

Upvotes: 1

Views: 1193

Answers (1)

Martin
Martin

Reputation: 4816

More than likely, you're importing either Fragment or FragmentTransaction from the support library and the other from the non-support library. Make sure any Fragment pieces you import are all from the same place. I've had similar problems with fragments.

Upvotes: 5

Related Questions