1

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?

4

1 回答 1

5

您很可能从支持库中导入 Fragment 或 FragmentTransaction,而从非支持库中导入另一个。确保您导入的所有片段都来自同一个地方。我在片段方面遇到过类似的问题。

于 2013-11-05T21:45:30.207 回答