Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method add(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, Fragment, String)

I have this problem ..

The method add(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, Fragment, String)

when using the following code inside a FragenmtActivity

getSupportFragmentManager().beginTransaction().add(com.korovyansk.android.slideout.R.id.slideout_placeholder,  ((Fragment)new CommentsMenuFragment()), "menu").commit();

where CommentsMenuFragment implementation is :

public class CommentsMenuFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_comment, container, false);
        ListView lvComments = (ListView) view.findViewById(R.id.lvComments);



        return view;
    }

}
like image 434
Adham Avatar asked Mar 20 '13 07:03

Adham


People also ask

How to add fragment in activity XML?

Add a fragment to an activity You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.

How to add fragment in activity in Android programmatically?

To programmatically add or remove a Fragment, you will need the FragmentManager and FragmentTransaction instances. Simply stated and per the Android documentation, a FragmentManager manages the fragments in an Activity. Obtain the FragmentManager by calling getFragmentManager( ) in an Activity.

What is FragmentTransaction in Android?

At runtime, a FragmentManager can add, remove, replace, and perform other actions with fragments in response to user interaction. Each set of fragment changes that you commit is called a transaction, and you can specify what to do inside the transaction using the APIs provided by the FragmentTransaction class.


1 Answers

Check if your CommentsMenuFragment extends from android.support.v4.app.Fragment instead of android.app.Fragment.

like image 100
PaNaVTEC Avatar answered Oct 12 '22 20:10

PaNaVTEC