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;
}
}
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.
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.
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.
Check if your CommentsMenuFragment extends from android.support.v4.app.Fragment instead of android.app.Fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With