Monday 18 February 2013

Nested Fragments

Previously we have learned some basics about using Fragments inside activtiy.

Fragments are very useful. However until recently fragments could not be used inside other fragment. That is you Activty can have multiple fragments ,but fragments cannot have fragments inside them.

With Android 4.2 APIv17 there was support for Nested Fragments Where you can use fragment inside other fragment. However there is a limitation that your fragment must be dynamic. There is no option to use <fragment> tags.

Here's a demo of using fragment inside fragment.

We will make use of our sample that we have been working in previous posts. We will change FragmentA. Here's a new Layout for FragmentA.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I am FragmentA" />

<FrameLayout
        android:id="@+id/child_fragment"
        android:layout_width="fill_parent"
        android:layout_height="200dip" />

</LinearLayout>

We use FrameLayout wherever we want our fragment to be . And so the updated FragmentA will be

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
public class FragmentA extends Fragment {
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View view = (View) inflater.inflate(R.layout."name of layout",
    container, false);
      return view ;
   }
}

Now the child Fragment let it be FragmentC
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
public class FragmentC extends Fragment {
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      TextView textView=new TextView(getActivity());
      textView.setText("Hello I am fragment C");
      return textView;
   }
}
And to add it dynamically to your FragmentA
Fragment fragmentC = new FragmentC();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.child_fragment, fragmentC ).commit();
Use getParentFragment() to get the reference to parent similar to getActivity that gives reference of parent Activtiy.

104 comments:

  1. otr214427
    INTERNATIONAL CONCEPT OF WORK FROM HOME
    Work from home theory is fast gaining popularity because of the freedom and flexibility that comes with it. Since one is not bound by fixed working hours, they can schedule their work at the time when they feel most productive and convenient to them. Women & Men benefit a lot from this concept of work since they can balance their home and work perfectly. People mostly find that in this situation, their productivity is higher and stress levels lower. Those who like isolation and a tranquil work environment also tend to prefer this way of working. Today, with the kind of communication networks available, millions of people worldwide are considering this option.

    Women & Men who want to be independent but cannot afford to leave their responsibilities at home aside will benefit a lot from this concept of work. It makes it easier to maintain a healthy balance between home and work. The family doesn't get neglected and you can get your work done too. You can thus effectively juggle home responsibilities with your career. Working from home is definitely a viable option but it also needs a lot of hard work and discipline. You have to make a time schedule for yourself and stick to it. There will be a time frame of course for any job you take up and you have to fulfill that project within that time frame.

    There are many things that can be done working from home. A few of them is listed below that will give you a general idea about the benefits of this concept.

    Baby-sitting
    This is the most common and highly preferred job that Women & Men like doing. Since in today's competitive world both the parents have to work they need a secure place to leave behind their children who will take care of them and parents can also relax without being worried all the time. In this job you don't require any degree or qualifications. You only have to know how to take care of children. Parents are happy to pay handsome salary and you can also earn a lot without putting too much of an effort.

    Nursery
    For those who have a garden or an open space at your disposal and are also interested in gardening can go for this method of earning money. If given proper time and efforts nursery business can flourish very well and you will earn handsomely. But just as all jobs establishing it will be a bit difficult but the end results are outstanding.

    Freelance
    Freelance can be in different wings. Either you can be a freelance reporter or a freelance photographer. You can also do designing or be in the advertising field doing project on your own. Being independent and working independently will depend on your field of work and the availability of its worth in the market. If you like doing jewellery designing you can do that at home totally independently. You can also work on freelancing as a marketing executive working from home. Wanna know more, email us on workfromhome.otr214427@gmail.com and we will send you information on how you can actually work as a marketing freelancer.


    Internet related work
    This is a very vast field and here sky is the limit. All you need is a computer and Internet facility. Whatever field you are into work at home is perfect match in the software field. You can match your time according to your convenience and complete whatever projects you get. To learn more about how to work from home, contact us today on workfromhome.otr214427@gmail.comand our team will get you started on some excellent work from home projects.


    Diet food
    Since now a days Women & Men are more conscious of the food that they eat hence they prefer to have homemade low cal food and if you can start supplying low cal food to various offices then it will be a very good source of income and not too much of efforts. You can hire a few ladies who will help you out and this can be a good business.

    Thus think over this concept and go ahead.

    ReplyDelete
  2. hi frnds please tell me....
    How to call one fragment to another fragment from BaseAdapter class onClickListener and pass datas...

    ReplyDelete
  3. hi frnds please tell me....
    How to call one fragment to another fragment from BaseAdapter class onClickListener and pass datas...

    ReplyDelete
  4. Nice Article.. Thank you for the information..

    ReplyDelete
  5. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    Android Training in chennai | Android Training

    ReplyDelete
  6. Thank you... it helped me ...

    ReplyDelete
  7. DUDEEE!!! THANKS A BUNCH!!! Life saviour!!

    ReplyDelete
  8. Thanks a lot.We will you have to share this blog content information increase with my knowledge learning skills.We develop to that's our info creative was really good.
    devops training
    devops online training
    devops training institute
    top 10 devops online training institute

    ReplyDelete
  9. Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    Android Training in chennai | Android Training in chennai with placement

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Thanks a lot.
    http://www.gyankidukan.com

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in Chennai | rpa training in pune

    rpa online training | rpa training in bangalore

    ReplyDelete
  14. I would like to thank you for your nicely written post, its informative and your writing style encouraged me to read it till end. Thanks

    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  15. Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, anyways I am here now and would just like to say thanks for a tremendous post. Please do keep up the great work.
    python training in pune
    python training institute in chennai
    python training in Bangalore

    ReplyDelete
  16. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.


    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  17. Attend The Python Training in Hyderabad From ExcelR. Practical Python Training Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python Training in Hyderabad.
    python training in bangalore

    ReplyDelete
  18. I am really happy to say it’s an interesting post to read. I learn new information from your article; you are doing a great job. Keep it up. Now i am waiting for more updates for machine learning course.

    ReplyDelete
  19. In this modern era, Data Analytics provides a business analytics course with placement subtle way to analyse the data in a qualitative and quantitative manner to draw logical conclusions. Gone are the days where one has to think about gathering the data and saving the data to form the clusters. For the next few years, it’s all about Data Analytics and it’s techniques to boost the modern era technologies such as Machine learning and Artificial Intelligence.

    ReplyDelete
  20. Video chat with strangers instantly on Me2Call4u. Our random video chat app is the perfect way to chat with strangers and meet cool new people instantly.

    ReplyDelete
  21. Good to become visiting your weblog again, it has been months for me. Nicely this article that i've been waited for so long. I will need this post to total my assignment in the college, and it has exact same topic together with your write-up. Thanks, good share.
    ExcelR Data Analytics Course

    ReplyDelete
  22. I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read !! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site.
    Please check ExcelR Data Science Certification

    ReplyDelete
  23. Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!. data science course Bangalore

    ReplyDelete
  24. Good to become visiting your weblog again, it has been months for me. Nicely this article that i've been waited for so long. I will need this post to total my assignment in the college, and it has exact same topic together with your write-up. Thanks, good share.!. data science courses

    ReplyDelete
  25. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    You can reach us:
    https://www.excelr.com/data-science-course-training-in-mumbai

    ExcelR - Data Science, Data Analytics, Business Analytics Course Training in Mumbai

    304, 3rd Floor, Pratibha Building. Three Petrol pump, Opposite Manas Tower, LBS Rd, Pakhdi, Thane West, Thane, Maharashtra 400602

    Contact Number: 18002122120.

    data science course in mumbai

    ReplyDelete
  26. I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!! best data science course in Bangalore

    ReplyDelete
  27. do like my blog for latest android studio tutorials guys@CATECh

    ReplyDelete
  28. Thanks for sharing such a wonderful blog with us. It makes the business develop more and more.
    DevOps Training In Hyderabad

    ReplyDelete
  29. I use this same code but the problem is
    Current fragment overlapping on next fragment
    Current fragment does not removed
    And i added addtobackstack but the problem occurs same
    Any solution regarding this.

    ReplyDelete
  30. I have recently visited your blog profile. I am totally impressed by your blogging skills and knowledge.
    Data Science Course in Hyderabad

    ReplyDelete
  31. Attend online training from one of the best training institute Data Science Training in Hyderabad

    ReplyDelete
  32. The Basics You Have Explained Was Good.Thanks For Sharing The Content With Us.

    Python Training Course Institute in Hyderabad

    ReplyDelete
  33. Thankyou for this wondrous post, I am happy I watched this site on yippee. ExcelR Data Analytics Courses In Pune

    ReplyDelete
  34. Very useful information, the post shared was very nice.
    Data Science Online Training

    ReplyDelete
  35. A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.
    data science courses

    ReplyDelete
  36. Very interesting to read this article.I would like to thank you for the efforts. I also offer Data Scientist Courses data scientist courses

    ReplyDelete
  37. Nice Post. I like your blog. Thanks for Sharing.
    Python Online Training

    ReplyDelete
  38. Thanks for sharing this information. I really Like Very Much.
    devops online training

    ReplyDelete
  39. Thank you for taking the time to publish this information very useful!ExcelR Business Analytics Courses

    ReplyDelete
  40. The AWS certification course has become the need of the hour for freshers, IT professionals, or young entrepreneurs. AWS is one of the largest global cloud platforms that aids in hosting and managing company services on the internet. It was conceived in the year 2006 to service the clients in the best way possible by offering customized IT infrastructure. Due to its robustness, Digital Nest added AWS training in Hyderabad under the umbrella of other courses

    ReplyDelete
  41. It’s difficult to find experienced people for this subject, however, you sound like you know what you’re talking about! Thanks
    data scientist training and placement

    ReplyDelete
  42. thanks for sharing your experiment about android .very useful.Angular training in Chennai

    ReplyDelete
  43. AMAZING BACHELORETTE PARTY SUPPLIES We strive to have a positive impact on small to medium businesses, customers, employees, the economy, and communities. Surjmor bring together smart, passionate builders with different backgrounds and goals, who share a common desire to always be learning and inventing on behalf of our customers. With all the family of business that are a part of us, our goals is providing customers with the best service possible.

    xxxtoys.top

    ReplyDelete
  44. This was a very meaningful post, so informative and encouraging information, Thank you for this post.

    on demand mobile application development

    ReplyDelete
  45. Experiments with Android, thanks for sharing on this topic android

    Data Science Training in Pune

    ReplyDelete
  46. Our the purpose is to share the reviews about the latest Jackets,Coats and Vests also share the related Movies,Gaming, Casual,Faux Leather and Leather materials available. Knights Varsity Jacket

    ReplyDelete
  47. Some may stag in Interviews!!! OOPS!! More than 50% of students do this in their career. Instead, do Hadoop Training in Chennai at Infycle. Those students can easily clear this Interview session because more than 5 times at INFYCLE practicing mock-interview sessions, Hence students are Getting out of their interview fear.

    ReplyDelete
  48. Viably, the article is actually the best point on this library related issue. I fit in with your choices and will enthusiastically foresee your next updates. business analytics course in mysore

    ReplyDelete
  49. I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. RPD Vest

    ReplyDelete
  50. I love to recommend you Where can crawl Exciting Products latest Jackets, Coats and Vests Click Here James Bond Black Jacket

    ReplyDelete
  51. Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.
    data analytics courses in hyderabad with placements

    ReplyDelete
  52. Incredible blog here! It's mind boggling posting with the checked and genuinely accommodating data. Tom Holland Uncharted Leather Jacket

    ReplyDelete
  53. Great post. keep sharing such a worthy information.
    Hadoop Training in Chennai

    ReplyDelete
  54. Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on. data scientist course in mysore

    ReplyDelete
  55. This is a well-written and comprehensive essay about utilizing nested fragments in Android programming. The inclusion of code samples and examples makes it simple to understand. Thank you for providing this useful information!
    Data Analytics Courses in India

    ReplyDelete
  56. "Thanks for sharing this insightful guide on nested fragments! It's a great resource for developers looking to leverage the power of fragments within fragments. Your clear explanations and code examples make it easy to understand and implement. Keep up the good work!"
    Data Analytics Courses In Bangalore

    ReplyDelete
  57. This is an excellent description of nested fragments in Android, complete with code samples. Thank you for your contribution!
    Data Analytics Courses in Delhi

    ReplyDelete
  58. Like a puzzle putting complete, this post took me on a voyage into the universe of nested fragments. It sounds like a great method to create dynamic apps with Android, therefore I can't wait to try it out in my own projects!
    Data Analytics Courses in Agra

    ReplyDelete
  59. An article discussing nested fragments in the context of software development, likely providing insights into this important aspect of user interface design and programming.

    Data Analytics Courses In Kochi



    ReplyDelete
  60. The author provides a clear and informative guide to using nested fragments in Android. The step-by-step instructions and code snippets make it easy to understand and implement. Great job on sharing this valuable information!
    Is iim skills fake?

    ReplyDelete
  61. This article provides a great explanation of Android's nested fragments along with code examples. I appreciate your contribution.
    Data Analytics Courses in Agra

    ReplyDelete
  62. Hello,
    Your blog post on nested fragments in Android is both informative and well-structured. It provides a clear explanation of this valuable feature, making it easy for developers to implement. Great work.
    Data Analytics Courses In Dubai

    ReplyDelete
  63. Wow, it is very beautiful and amazing; as a result, it has been incredibly helpful in helping me understand numerous things. It is extremely well explained, and your writing provided me with further information. Data Analytics Courses In Pune

    ReplyDelete
  64. Your article on Nested Fragments provides valuable insights and guidance for developers navigating this complex topic. Keep up the good work.
    Data Analytics Courses In Chennai

    ReplyDelete
  65. good blog
    Data Analytics Courses In Vadodara

    ReplyDelete
  66. This blog opened my mind to nested fragments - like Russian dolls of information. I'm excited to experiment with this in my own projects!
    Data Analytics Courses In Gujarat

    ReplyDelete
  67. Mind blown! Learning about nested fragments was like uncovering hidden treasures in the world of Android development. Thanks for this gem of a post!
    Data Analytics Courses In Gujarat

    ReplyDelete
  68. Mind blown! Nested fragments opened up a world of possibilities. Can't wait to experiment with this in my own projects.
    Data Analytics Courses In Gujarat

    ReplyDelete
  69. nice blog
    Data Analytics Courses In Vadodara

    ReplyDelete
  70. Your blog post effectively highlighted the significance of using nested fragments for creating more dynamic and feature-rich applications.
    Digital Marketing Courses in Hamburg

    ReplyDelete
  71. Thank you for sharing your knowledge on this topic. I've learned a lot from your post.Best AWS Training in Pune with Placement

    ReplyDelete
  72. Nested fragments in programming allow for the modular organization of code and user interfaces, enhancing flexibility and maintainability. In the realm of data analytics, London offers a diverse range of Data Analytics courses that equip professionals with the skills and knowledge to excel in the dynamic field of data-driven decision-making. Please also Digital Marketing Courses in London.

    ReplyDelete
  73. the post was great and the content was also really helpful
    Data Analytics With Python

    ReplyDelete
  74. "Your comprehensive explanation of nested fragments in Android development offers valuable insights into the benefits of creating modular UI designs and facilitating code reusability.
    Digital marketing courses in woking

    ReplyDelete
  75. The blog provides excellent and detailed explanation on Nested Fragments thanks for sharing valuable and informative resource.
    Digital Marketing Courses in Italy

    ReplyDelete
  76. Thank you for sharing clear and concise explanation on Nested Fragments.
    data analyst courses in limerick

    ReplyDelete
  77. Than you for sharing in depth knowledge and insightful demo on Nested Fragments.
    Digital Marketing Courses In Bhutan

    ReplyDelete
  78. I particularly appreciate how you've woven practical tips and lessons learned throughout the post, creating a guide of sorts for others venturing into Android development. The inclusion of specific projects and the thought process behind them adds depth to the narrative, making it both informative and inspiring. Digital Marketing Courses In Norwich

    ReplyDelete
  79. Thank you for providing great and fantastic explanation on Nested Fragments.
    Adwords marketing

    ReplyDelete
  80. Clear and concise tutorial on implementing Nested Fragments! Your writing effortlessly guides you through the process, making it easy to understand. Thanks for sharing this valuable information.

    How Digital marketing is changing business

    ReplyDelete
  81. Android's Nested Fragments, introduced in APIv17, enable fragment nesting within other fragments, a feature initially unavailable. This functionality allows for dynamic fragment utilization within fragment containers, enhancing modularity and flexibility in app development. While tags are unsupported, leveraging Nested Fragments empowers developers to create more intricate and layered UI structures within Android applications, enriching user experiences and design possibilities.
    Data Analytics courses in new york

    ReplyDelete
  82. A good blog always comes up with new and exciting information and while reading I felt that this blog really has all those qualities that qualify a blog to be one.
    Investment Banking courses in bangalore

    ReplyDelete
  83. The blog post provides insightful knowledge on Nested Fragments, thanks for sharing valuable post.
    Investment banking training Programs

    ReplyDelete