I have a fragment I am trying to add into a view.
FragmentManager fragMgr=getSupportFragmentManager(); feed_parser_activity content = (feed_parser_activity)fragMgr .findFragmentById(R.id.feedContentContainer); FragmentTransaction xaction=fragMgr.beginTransaction(); if (content == null || content.isRemoving()) { content=new feed_parser_activity(item.getLink().toString()); xaction .add(R.id.feedContentContainer, content) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .addToBackStack(null) .commit(); Log.e("Abstract", "DONE"); }
When this code is executed I get the following error in debug..
java.lang.IllegalArgumentException: No view found for id 0x7f080011 for fragment feed_parser_activity{41882f50 #2 id=0x7f080011}
feed_parser_activity
is a Fragment that is set to Fragment layout in xml.
I am using a FragmentActivity to host the Fragment Layout holding the feed_parser_layout
.
Am I coding this correctly above?
FragmentContainerView is a customized Layout designed specifically for Fragments. It extends FrameLayout , so it can reliably handle Fragment Transactions, and it also has additional features to coordinate with fragment behavior.
android.R.id.content gives you the root element of a view, without having to know its actual name/type/ID.
onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view hierarchy associated with the fragment. onActivityCreated(Bundle) tells the fragment that its activity has completed its own Activity.
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.
I was having this problem too, until I realized that I had specified the wrong layout in setContentView()
of the onCreate()
method of the FragmentActivity.
The id passed into FragmentTransaction.add()
, in your case R.id.feedContentContainer
, must be a child of the layout specified in setContentView()
.
You didn't show us your onCreate()
method, so perhaps this is the same problem.
This error also occurs when having nested Fragments and adding them with getSupportFragmentManager() instead of getChildFragmentManager().
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