সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
একটি Fragment আপনার অ্যাপের UI এর একটি পুনঃব্যবহারযোগ্য অংশ উপস্থাপন করে। একটি খণ্ডটি তার নিজস্ব লেআউটকে সংজ্ঞায়িত করে এবং পরিচালনা করে, এর নিজস্ব জীবনচক্র রয়েছে এবং এর নিজস্ব ইনপুট ইভেন্টগুলি পরিচালনা করতে পারে। টুকরোগুলো নিজেরা বাঁচতে পারে না। তাদের অবশ্যই একটি কার্যকলাপ বা অন্য একটি অংশ দ্বারা হোস্ট করা উচিত। ফ্র্যাগমেন্টের ভিউ হায়ারার্কি হোস্টের ভিউ হায়ারার্কির অংশ হয়ে যায় বা সংযুক্ত হয় ।
মডুলারিটি
টুকরাগুলি আপনাকে UI কে বিচ্ছিন্ন অংশে বিভক্ত করতে দিয়ে আপনার কার্যকলাপের UI-তে মডুলারিটি এবং পুনরায় ব্যবহারযোগ্যতার পরিচয় দেয়। ক্রিয়াকলাপগুলি আপনার অ্যাপের ইউজার ইন্টারফেসের চারপাশে বৈশ্বিক উপাদানগুলি রাখার জন্য একটি আদর্শ জায়গা, যেমন একটি নেভিগেশন ড্রয়ার৷ বিপরীতভাবে, একটি একক স্ক্রীন বা স্ক্রিনের অংশের UI সংজ্ঞায়িত এবং পরিচালনা করার জন্য টুকরোগুলি আরও উপযুক্ত।
এমন একটি অ্যাপ বিবেচনা করুন যা বিভিন্ন স্ক্রীন আকারে সাড়া দেয়। বড় স্ক্রিনে, আপনি অ্যাপটিকে একটি স্ট্যাটিক নেভিগেশন ড্রয়ার এবং গ্রিড লেআউটে একটি তালিকা প্রদর্শন করতে চাইতে পারেন। ছোট স্ক্রিনে, আপনি অ্যাপটিকে একটি নীচের নেভিগেশন বার এবং একটি লিনিয়ার লেআউটে একটি তালিকা প্রদর্শন করতে চাইতে পারেন।
ক্রিয়াকলাপে এই বৈচিত্রগুলি পরিচালনা করা দুর্বোধ্য। বিষয়বস্তু থেকে নেভিগেশন উপাদানগুলি পৃথক করা এই প্রক্রিয়াটিকে আরও পরিচালনাযোগ্য করে তুলতে পারে। তারপরে কার্যকলাপটি সঠিক নেভিগেশন UI প্রদর্শনের জন্য দায়ী, যখন খণ্ডটি সঠিক বিন্যাস সহ তালিকাটি প্রদর্শন করে।
চিত্র 1. একই স্ক্রিনের দুটি সংস্করণ বিভিন্ন স্ক্রীন আকারে। বাম দিকে, একটি বড় পর্দায় একটি নেভিগেশন ড্রয়ার রয়েছে যা কার্যকলাপ দ্বারা নিয়ন্ত্রিত হয় এবং একটি গ্রিড তালিকা যা খণ্ড দ্বারা নিয়ন্ত্রিত হয়৷ ডানদিকে, একটি ছোট পর্দায় একটি নীচের নেভিগেশন বার রয়েছে যা কার্যকলাপ দ্বারা নিয়ন্ত্রিত হয় এবং একটি রৈখিক তালিকা যা খণ্ড দ্বারা নিয়ন্ত্রিত হয়৷
আপনার UI কে খন্ডে বিভক্ত করা রানটাইমে আপনার কার্যকলাপের চেহারা পরিবর্তন করা সহজ করে তোলে। আপনার কার্যকলাপ STARTEDজীবনচক্র অবস্থায় বা উচ্চতর অবস্থায় থাকাকালীন, খন্ডগুলি যোগ করা, প্রতিস্থাপন করা বা সরানো যেতে পারে। এবং আপনি একটি ব্যাক স্ট্যাকে এই পরিবর্তনগুলির একটি রেকর্ড রাখতে পারেন যা কার্যকলাপ দ্বারা পরিচালিত হয়, যাতে পরিবর্তনগুলি বিপরীত করা যায়।
আপনি একই ক্রিয়াকলাপের মধ্যে, একাধিক ক্রিয়াকলাপে বা এমনকি অন্য খণ্ডের শিশু হিসাবে একই খণ্ড শ্রেণীর একাধিক উদাহরণ ব্যবহার করতে পারেন। এটি মাথায় রেখে, শুধুমাত্র তার নিজস্ব UI পরিচালনা করার জন্য প্রয়োজনীয় যুক্তি সহ একটি খণ্ড প্রদান করুন৷ এক টুকরো থেকে অন্য অংশের উপর নির্ভর করা বা ম্যানিপুলেট করা এড়িয়ে চলুন।
পরবর্তী পদক্ষেপ
খণ্ডের সাথে সম্পর্কিত আরও ডকুমেন্টেশন এবং সংস্থানগুলির জন্য, নিম্নলিখিতটি দেখুন।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Fragments\n\nA [`Fragment`](/reference/androidx/fragment/app/Fragment) represents a\nreusable portion of your app's UI. A fragment defines and manages its own\nlayout, has its own lifecycle, and can handle its own input events. Fragments\ncan't live on their own. They must be *hosted* by an activity or another\nfragment. The fragment's view hierarchy becomes part of, or *attaches to*,\nthe host's view hierarchy.\n| **Note:** Some [Android Jetpack](/jetpack/androidx/versions) libraries, such as [Navigation](/guide/navigation), [`BottomNavigationView`](/reference/com/google/android/material/bottomnavigation/BottomNavigationView), and [`ViewPager2`](/jetpack/androidx/releases/viewpager2), are designed to work with fragments.\n\nModularity\n----------\n\nFragments introduce modularity and reusability into your activity's UI by\nletting you divide the UI into discrete chunks. Activities are an ideal\nplace to put global elements around your app's user interface, such as a\nnavigation drawer. Conversely, fragments are better suited to define and\nmanage the UI of a single screen or portion of a screen.\n\nConsider an app that responds to various screen sizes. On larger screens, you\nmight want the app to display a static navigation drawer and a list in a grid\nlayout. On smaller screens, you might want the app to display a bottom\nnavigation bar and a list in a linear layout.\n\nManaging these variations in the activity is\nunwieldy. Separating the navigation elements from the content can make this\nprocess more manageable. The activity is then responsible for displaying\nthe correct navigation UI, while the fragment displays the list with the proper\nlayout.\n**Figure 1.** Two versions of the same screen on different screen sizes. On the left, a large screen contains a navigation drawer that is controlled by the activity and a grid list that is controlled by the fragment. On the right, a small screen contains a bottom navigation bar that is controlled by the activity and a linear list that is controlled by the fragment.\n\nDividing your UI into fragments makes it easier to modify your activity's\nappearance at runtime. While your activity is in the `STARTED`\n[lifecycle state](/guide/components/activities/activity-lifecycle) or\nhigher, fragments can be added, replaced, or removed. And you can keep a record\nof these changes in a back stack that is managed by the activity, so that\nthe changes can be reversed.\n\nYou can use multiple instances of the same fragment class within the\nsame activity, in multiple activities, or even as a child of another\nfragment. With this in mind, only provide a fragment with\nthe logic necessary to manage its own UI. Avoid depending on or\nmanipulating one fragment from another.\n\nNext steps\n----------\n\nFor more documentation and resources related to fragments, see the following.\n\n### Getting Started\n\n- [Create a fragment](/guide/fragments/create)\n\n### Further topics\n\n- [Fragment manager](/guide/fragments/fragmentmanager)\n- [Fragment transactions](/guide/fragments/transactions)\n- [Navigate between fragments using animations](/guide/fragments/animate)\n- [Fragment lifecycle](/guide/fragments/lifecycle)\n- [Saving state with fragments](/guide/fragments/saving-state)\n- [Communicate with fragments](/guide/fragments/communicate)\n- [Working with the AppBar](/guide/fragments/appbar)\n- [Display dialogs with DialogFragment](/guide/fragments/dialogs)\n- [Debug your fragments](/guide/fragments/debugging)\n- [Test your fragments](/guide/fragments/test)\n\n### Samples\n\n### Videos\n\n- [Single Activity: Why, when, and how (Android Dev Summit '18)](https://www.youtube.com/watch?v=2k8x8V77CrU)\n- [Fragments: Past, present, and future (Android Dev Summit '19)](https://www.youtube.com/watch?v=RS1IACnZLy4)"]]