I examine code example from FragmentBasics.zip
http://developer.android.com/training/basics/fragments/communicating.html
There was this code (MainActivity.java):
ArticleFragment articleFrag = (ArticleFragment)
getSupportFragmentManager().findFragmentById(R.id.article_fragment);
But I never find *article_fragment* declared/set anywhere in the whole classes or layouts(xml) or values. Where does it come from??
This is the XML code used in res\layout-large\news_articles.xml:
<fragment android:name="com.example.android.fragments.HeadlinesFragment"
android:id="@+id/headlines_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.android.fragments.ArticleFragment"
android:id="@+id/article_fragment"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
The fragment with the android:name="com.example.android.fragments.ArticleFragment attribute has the id set as: @+id/article_fragment
The JAVA code where you find the id article_fragment being used is on line 55 for this method: public void onArticleSelected(int position). It checks if your are using a two-pane layout. That is why the XML file mentioned at the top, is in the layout-large foldr (In the example).
R.id.article_fragment layout is used for large screen device in current example
you can find out this layout inside res/layout-large/news_articles.xml
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