Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your Class that extends <code>FragmentActivity</code> you are setting the view to an XML file titled <code>activity_main</code>. Inside of <code>activity_main</code> you have a reference to your <em>Fragment</em> code, <code>com.example.fragtest.FragOne</code>. When that XML is loaded, the code associated with <code>com.example.fragtest.FragOne</code> is executed. That <em>Fragment</em>'s code returns a <em>View</em> with the <code>R.id.activity_main</code>.</p> <p>That XML file has a reference to the same <em>Fragment</em> code that had just instantiated it. You see the conundrum.</p> <p>To resolve your issue instance a new XML file (one that is not named <code>activity_main</code>) in your <em>Fragment</em> class. Instead of inflating <code>activity_main</code> inflate a separate XML (one that does not contain a reference to the code that called it). Effectively <code>activity_main</code> should be the container, this new layout (for instance <code>fragment_layout</code>) will be the UI portion.</p> <p>I like to think of it like this: Despite doctrine, a <em>Fragment</em> has three portions. The container <em>Activity</em> (this can, and in your case should, inflate a layout XML file via setContentView), the <em>Fragment</em>'s java code (this can, and in your case should, inflate a layout....something other than <code>activity_main</code>), and that <em>Fragment</em>'s associated XML file (the one that is inflated by your Fragment class, don't include a cyclical reference back to it's code).</p> <p>There are, of course, loopholes to these mantras but you get the drift?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload