avatarSatya Pavan Kantamani

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1823

Abstract

e fire alarm rang. It was a fire drill.</p><p id="09ee">The fire alarm rang, but it was a fire drill.</p><h1 id="bab4">Rule 2: Use commas to separate nouns of direct address</h1><p id="0e85">Note: A noun of direct address names the noun (person) to whom the speaker is speaking.</p><p id="bc01"><b>Examples:</b></p><p id="cac0">Come in, Steve, and close the door.</p><p id="1844">Steve, come in and close the door.</p><p id="0543">Come in and close the door, Steve.</p><h1 id="8001">Rule 3: Use commas to separate an appositive</h1><p id="37ad"><b>Note:</b> Appositive are words placed immediately after other words that carry the same meaning and add clarity.</p><p id="e223"><b>Example:</b></p><p id="301d">Mrs. Gross is in Florida<b>.</b></p><p id="77cd">Mrs. Gross, my aunt, is in Florida.</p><h1 id="7f0c">Rule 4: Use commas to set off words that interrupt the sentence</h1><p id="ea4e"><b>Example:</b></p><p id="92b3">The fabric is pre-shrunk.</p><p id="aa46">This fabric, on the other hand, is pre-shrunk.</p><h1 id="20b2">Rule 5: Use commas to separate introductory words or phrases from the base sentence</h1><p id="5fc6"><b>Examples:</b></p><p id="4422">Bill sat through the horror film.</p><p id="c704">Closing his eyes, Bill sat through the horror film.</p><p id="6a65">Yes, Bill sat through the horror film.</p><h1 id="7331">Rule 6: Use commas after every item in a list except the last</h1><p id="a933"><b>Note:</b> Follow this rule with nouns and verbs.</p><p id="f3e7"><b>Examples:</b></p><p id="6d66">Sam, Susan, Steve and Scott went home. (nouns)</p><p id="e5f6">The dog barked, jumped and rolled over. (verbs)</p><h1 id="ca7b">Rule 7: Use commas to separate two or more adjectives that describe a noun</h1><p id="1c90"><b>Note:</b> Adjectives are descriptive words.</p><p id="b208"><b>Example:</b></p><p

Options

id="6230">The bright, yellow sun illuminated the sky.</p><h1 id="3306">Rule 8: Use commas to separate a quote from the tag line</h1><p id="a919"><b>Note: </b>A quote states exactly what the speaker said. A tag line explains the quote.</p><p id="4a93"><b>Examples:</b></p><p id="87a3">“The mayor,” stated Peter, “has brown hair.”</p><p id="5d53">Peter stated, “The Mayor has brown hair.”</p><p id="0faa">“The Mayor has brown hair,” stated Peter.</p><h1 id="2636">Rule 9: Use commas in dates, addresses, and numbers</h1><p id="00c4"><b>Examples:</b></p><p id="44b2">Friday, October 13, 1977</p><p id="5701">1334 Maple Road, William, New York 14221</p><p id="317a">12,000</p><p id="5f4c">These rules provide a simple list to save and reference when you are unsure about comma placement.</p><div id="0811" class="link-block"> <a href="https://bmahler-55533.medium.com/membership"> <div> <div> <h2>Join Medium with my referral link - Brenda Mahler</h2> <div><h3>Read every story from Brenda Mahler (and thousands of other writers on Medium). Your membership fee directly supports…</h3></div> <div><p>bmahler-55533.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*NI3JeOLnl_ZBoZWf)"></div> </div> </div> </a> </div><h2 id="0eca">If you found this helpful, follow Strategies for Writing, a space for writers offering a series of posts in a question — answer format. Each article supports writers with inspiration and responses to questions you’ve always wondered about.</h2><h2 id="2d43">Posts require only 2–4 minutes to read so writers have time to write. Visit often!</h2></article></body>

What Is a Target Fragment?

How to effectively communicate from a ChildFragment to a ParentFragment in Android

A fragment is a piece of an application’s user interface or behavior that can be placed in an activity.

Interaction with fragments is done through FragmentManager, which can be obtained via Activity.getFragmentManager() and Fragment.getFragmentManager().

A fragment is closely tied to the activity it is in and can not be used apart from one. Although a fragment defines its own lifecycle, that lifecycle is dependent on its activity. If the activity is stopped, no fragments inside of it can be started. When the activity is destroyed, all fragments will be destroyed.

There are various ways to communicate between fragments like Interface, shared ViewModel, etc.

But did you know that we can easily communicate from child fragment to parent fragment and receive a callback in onActivityResult() in the parent fragment by using the standard methods setTargetFragment() and getTargetFragment()?

Use case

When we open a dialog fragment from where the user needs to select an option from a list of options available and later, when they click on the OK button, we need to return the selected option to the parent fragment.

Steps

  1. If we want to communicate from one fragment to another fragment then from ParentFragment we have to use setTargetFragment (ParentFragment instance, RequestCode).
  2. After that, we call the show() method on the dialog fragment to display a list of available options.
  3. Then use onActivityResult (RequestCode, Activity.RESULT_OK, intent). So, the callback from the ChildFragment can be received in the override method onActivityResult of ParentFragment.
  4. From the ChildFragment, we have to use getTargetFragment() which returns the ParentFragment instance if anything is set using setTargetFragment().

Let’s better understand it with an example.

Step 1: Let’s call showOptionsDialog() in the parent fragment which shows an OptionsDialogFragment with a list of options.

Step 2: Implement onActivityResult() in the ParentFragment where we receive the callback from ChildFragment and perform an action based on the result.

Step 3: When the user clicks on an option in the OptionsDialogFragment then call onExit(selection: String) where we write our logic to return the callback to ParentFragment.

From the documentation setTargetFragment().

From the documentation getTargetFragment().

/**
 * Return the target fragment set by {#setTargetFragment}.
 */
@Nullable
final public Fragment getTargetFragment() {
  ............
}

Please let me know your suggestions and comments.

Thanks for reading!

Android
Android App Development
Software Development
Programming
AndroidDev
Recommended from ReadMedium