Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@tonny</p> <p>i've download the FragmentBasics.zip. i only change the argument name.here is the code and result pic.</p> <p><strong>MainActivity</strong></p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.news_articles); // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first fragment if (findViewById(R.id.fragment_container) != null) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. if (savedInstanceState != null) { return; } // Create an instance of ExampleFragment HeadlinesFragment fragment = new HeadlinesFragment(); // In case this activity was started with special instructions from an Intent, // pass the Intent's extras to the fragment as arguments // firstFragment.setArguments(getIntent().getExtras()); //test Bundle args= new Bundle(); args.putString("category", "clothes"); args.putString("item", "shirts"); fragment.setArguments(args); // Add the fragment to the 'fragment_container' FrameLayout getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_container, fragment).commit(); } } </code></pre> <p><strong>HeadlinesFragment</strong></p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // We need to use a different list item layout for devices older than Honeycomb int layout = Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB ? android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1; Bundle args = getArguments(); if (args == null) { Toast.makeText(getActivity(), "arguments is null " , Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity(), "text " + args , Toast.LENGTH_LONG).show(); } // Create an array adapter for the list view, using the Ipsum headlines array setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), layout, Ipsum.Headlines)); } </code></pre> <p><strong>here is the result</strong></p> <p><img src="https://i.stack.imgur.com/JggbT.png" alt="enter image description here"></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. This table or related slice is empty.
    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