Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One possible way to fix this is to let the <code>Fragment</code> being created decide when it's safe to set its title. </p> <p>For example, you could pass the title in the constructor and keep it in a member variable.</p> <pre><code>RatingDialogFragment newFragment = new RatingDialogFragment("String"); </code></pre> <p>Then in your RatingDialogFragment:</p> <pre><code>... public RatingDialogFragment(String title) { mTitle = title; } ... </code></pre> <p>Somewhere in your RatingDialogFragment lifecycle, when it's safe to do so, actually set the title. </p> <pre><code>... @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Set title for this dialog getDialog().setTitle(mTitle); } </code></pre> <p><strong>Edit:</strong> It is worth noting that although this works in this particular case, a better general approach is to use <code>Fragment</code>'s ability to receive arguments via the <a href="http://developer.android.com/reference/android/app/Fragment.html#setArguments%28android.os.Bundle%29"><code>setArguments()</code></a> and <a href="http://developer.android.com/reference/android/app/Fragment.html#setArguments%28android.os.Bundle%29"><code>getArguments()</code></a> methods. This allows you to keep the default empty constructor there so that your fragment can be instantiated by the framework correctly (eg if you were introducing your Fragment via XML). An example can be <a href="http://developer.android.com/reference/android/app/DialogFragment.html#BasicDialog">found here</a>.</p> <p>From the <a href="http://developer.android.com/reference/android/app/Fragment.html#Fragment%28%29">documentation</a>:</p> <blockquote> <p>Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment with getArguments().</p> </blockquote>
    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