সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
চেকবক্স ব্যবহারকারীদের একটি তালিকা থেকে এক বা একাধিক আইটেম নির্বাচন করতে দেয়। ব্যবহারকারীকে নিম্নলিখিতগুলি করতে দিতে আপনি একটি চেকবক্স ব্যবহার করতে পারেন:
একটি আইটেম চালু বা বন্ধ করুন.
একটি তালিকার একাধিক বিকল্প থেকে নির্বাচন করুন।
চুক্তি বা স্বীকৃতি নির্দেশ করুন।
অ্যানাটমি
একটি চেকবক্স নিম্নলিখিত উপাদান নিয়ে গঠিত:
বাক্স : এটি চেকবক্সের জন্য ধারক।
চেক করুন : এটি একটি ভিজ্যুয়াল সূচক যা দেখায় যে চেকবক্সটি নির্বাচন করা হয়েছে কিনা।
লেবেল : এটি সেই পাঠ্য যা চেকবক্সের বর্ণনা দেয়।
রাজ্যগুলি
একটি চেকবক্স তিনটি অবস্থার একটিতে হতে পারে:
অনির্বাচিত : চেকবক্সটি নির্বাচন করা হয়নি। বাক্সটা খালি।
অনির্দিষ্ট : চেকবক্স একটি অনিশ্চিত অবস্থায় আছে। বাক্সে একটি ড্যাশ রয়েছে।
নির্বাচিত : চেকবক্স নির্বাচন করা হয়েছে। বাক্সে একটি চেকমার্ক রয়েছে।
নিচের ছবিটি একটি চেকবক্সের তিনটি অবস্থা প্রদর্শন করে।
চিত্র 1. একটি চেকবক্সের তিনটি অবস্থা। অনির্বাচিত, অনির্ধারিত এবং নির্বাচিত।
বাস্তবায়ন
আপনি আপনার অ্যাপে একটি চেকবক্স তৈরি করতে Checkbox কম্পোজেবল ব্যবহার করতে পারেন। মনে রাখার জন্য কয়েকটি মূল পরামিতি রয়েছে:
checked : বুলিয়ান যা ক্যাপচার করে যে চেকবক্সটি চেক করা হয়েছে বা আনচেক করা আছে কিনা।
onCheckedChange() : ব্যবহারকারী চেকবক্সে ট্যাপ করলে অ্যাপটি যে ফাংশনটি কল করে।
নিচের স্নিপেটটি দেখায় কিভাবে Checkbox কম্পোজেবল ব্যবহার করতে হয়:
@ComposablefunCheckboxMinimalExample(){varcheckedbyremember{mutableStateOf(true)}Row(verticalAlignment=Alignment.CenterVertically,){Text("Minimal checkbox")Checkbox(checked=checked,onCheckedChange={checked=it})}Text(if(checked)"Checkbox is checked"else"Checkbox is unchecked")}
এই কোডটি একটি চেকবক্স তৈরি করে যা প্রাথমিকভাবে আনচেক করা হয়। ব্যবহারকারী চেকবক্সে ক্লিক করলে, onCheckedChange lambda checked অবস্থা আপডেট করে।
ফলাফল
চেক না করা হলে এই উদাহরণটি নিম্নলিখিত উপাদান তৈরি করে:
চিত্র 2. টিক চিহ্নমুক্ত চেকবক্স
এবং এইভাবে চেক করা হলে একই চেকবক্স প্রদর্শিত হয়:
চিত্র 3. চেকবক্স চেক করা হয়েছে
উন্নত উদাহরণ
আপনি কীভাবে আপনার অ্যাপে চেকবক্সগুলি প্রয়োগ করতে পারেন তার আরও জটিল উদাহরণ নিচে দেওয়া হল। এই স্নিপেটে, একটি অভিভাবক চেকবক্স এবং একটি সিরিজ চাইল্ড চেকবক্স রয়েছে৷ ব্যবহারকারী যখন প্যারেন্ট চেকবক্সে ট্যাপ করে, অ্যাপটি সমস্ত চাইল্ড চেকবক্স চেক করে।
@ComposablefunCheckboxParentExample(){// Initialize states for the child checkboxesvalchildCheckedStates=remember{mutableStateListOf(false,false,false)}// Compute the parent state based on children's statesvalparentState=when{childCheckedStates.all{it}->ToggleableState.OnchildCheckedStates.none{it}->ToggleableState.Offelse->ToggleableState.Indeterminate}Column{// Parent TriStateCheckboxRow(verticalAlignment=Alignment.CenterVertically,){Text("Select all")TriStateCheckbox(state=parentState,onClick={// Determine new state based on current statevalnewState=parentState!=ToggleableState.OnchildCheckedStates.forEachIndexed{index,_->
childCheckedStates[index]=newState}})}// Child CheckboxeschildCheckedStates.forEachIndexed{index,checked->
Row(verticalAlignment=Alignment.CenterVertically,){Text("Option ${index+1}")Checkbox(checked=checked,onCheckedChange={isChecked->
// Update the individual child statechildCheckedStates[index]=isChecked})}}}if(childCheckedStates.all{it}){Text("All options selected")}}
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-08-28 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-08-28 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["Checkboxes let users select one or more items from a list. You might use a\ncheckbox to let the user do the following:\n\n- Turn an item on or off.\n- Select from multiple options in a list.\n- Indicate agreement or acceptance.\n\n| **Note:** Use checkboxes instead of [switches](/develop/ui/compose/components/switch) or [radio buttons](https://m3.material.io/components/radio-button) if the user can select multiple options in a list.\n\nAnatomy\n\nA checkbox consists of the following elements:\n\n- **Box**: This is the container for the checkbox.\n- **Check**: This is the visual indicator that shows whether the checkbox is selected or not.\n- **Label**: This is the text that describes the checkbox.\n\nStates\n\nA checkbox can be in one of three states:\n\n- **Unselected**: The checkbox is not selected. The box is empty.\n- **Indeterminate**: The checkbox is in an indeterminate state. The box contains a dash.\n- **Selected**: The checkbox is selected. The box contains a checkmark.\n\nThe following image demonstrates the three states of a checkbox.\n**Figure 1.** The three states of a checkbox. Unselected, indeterminate, and selected.\n\nImplementation\n\nYou can use the [`Checkbox`](/reference/kotlin/androidx/compose/material3/package-summary#Checkbox(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.CheckboxColors,androidx.compose.foundation.interaction.MutableInteractionSource)) composable to create a checkbox in your app.\nThere are just a few key parameters to keep in mind:\n\n- `checked`: The boolean that captures whether the checkbox is checked or unchecked.\n- `onCheckedChange()`: The function that the app calls when the user taps the checkbox.\n\nThe following snippet demonstrates how to use the `Checkbox` composable:\n\n\n```kotlin\n@Composable\nfun CheckboxMinimalExample() {\n var checked by remember { mutableStateOf(true) }\n\n Row(\n verticalAlignment = Alignment.CenterVertically,\n ) {\n Text(\n \"Minimal checkbox\"\n )\n Checkbox(\n checked = checked,\n onCheckedChange = { checked = it }\n )\n }\n\n Text(\n if (checked) \"Checkbox is checked\" else \"Checkbox is unchecked\"\n )\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/compose/snippets/src/main/java/com/example/compose/snippets/components/Checkbox.kt#L62-L81\n```\n\n\u003cbr /\u003e\n\nExplanation\n\nThis code creates a checkbox that is initially unchecked. When the user clicks\non the checkbox, the `onCheckedChange` lambda updates the `checked` state.\n\nResult\n\nThis example produces the following component when unchecked:\n**Figure 2.** Unchecked checkbox\n\nAnd this is how the same checkbox appears when checked:\n**Figure 3.** Checked checkbox\n\nAdvanced example\n\nThe following is a more complex example of how you can implement checkboxes in\nyour app. In this snippet, there is a parent checkbox and a series of child\ncheckboxes. When the user taps the parent checkbox, the app checks all child\ncheckboxes.\n\n\n```kotlin\n@Composable\nfun CheckboxParentExample() {\n // Initialize states for the child checkboxes\n val childCheckedStates = remember { mutableStateListOf(false, false, false) }\n\n // Compute the parent state based on children's states\n val parentState = when {\n childCheckedStates.all { it } -\u003e ToggleableState.On\n childCheckedStates.none { it } -\u003e ToggleableState.Off\n else -\u003e ToggleableState.Indeterminate\n }\n\n Column {\n // Parent TriStateCheckbox\n Row(\n verticalAlignment = Alignment.CenterVertically,\n ) {\n Text(\"Select all\")\n TriStateCheckbox(\n state = parentState,\n onClick = {\n // Determine new state based on current state\n val newState = parentState != ToggleableState.On\n childCheckedStates.forEachIndexed { index, _ -\u003e\n childCheckedStates[index] = newState\n }\n }\n )\n }\n\n // Child Checkboxes\n childCheckedStates.forEachIndexed { index, checked -\u003e\n Row(\n verticalAlignment = Alignment.CenterVertically,\n ) {\n Text(\"Option ${index + 1}\")\n Checkbox(\n checked = checked,\n onCheckedChange = { isChecked -\u003e\n // Update the individual child state\n childCheckedStates[index] = isChecked\n }\n )\n }\n }\n }\n\n if (childCheckedStates.all { it }) {\n Text(\"All options selected\")\n }\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/compose/snippets/src/main/java/com/example/compose/snippets/components/Checkbox.kt#L86-L136\n```\n\n\u003cbr /\u003e\n\nExplanation\n\nThe following are several points you should note from this example:\n\n- **State management** :\n - `childCheckedStates`: A list of booleans using `mutableStateOf()` to track the checked state of each child checkbox.\n - `parentState`: A [`ToggleableState`](/reference/kotlin/androidx/compose/ui/state/ToggleableState?_gl=1*1nllj9c*_up*MQ..*_ga*MTQ4MjE3NjI1Ny4xNzE1MzM1Nzc0*_ga_6HH9YJMN9M*MTcxNTMzNTc3NC4xLjAuMTcxNTMzNTc3NC4wLjAuMA..) whose value derives from the child checkboxes' states.\n- **UI components** :\n - [`TriStateCheckbox`](/reference/kotlin/androidx/compose/material3/package-summary#TriStateCheckbox(androidx.compose.ui.state.ToggleableState,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.CheckboxColors,androidx.compose.foundation.interaction.MutableInteractionSource)): Is necessary for the parent checkbox as it has a `state` param that lets you set it to indeterminate.\n - [`Checkbox`](/reference/kotlin/androidx/compose/material3/package-summary#Checkbox(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.CheckboxColors,androidx.compose.foundation.interaction.MutableInteractionSource)): Used for each child checkbox with its state linked to the corresponding element in `childCheckedStates`.\n - `Text`: Displays labels and messages (\"Select all\", \"Option X\", \"All options selected\").\n- **Logic** :\n - The parent checkbox's `onClick` updates all child checkboxes to the opposite of the current parent state.\n - Each child checkbox's `onCheckedChange` updates its corresponding state in the `childCheckedStates` list.\n - The code displays \"`All options selected`\" when all child checkboxes are checked.\n\n| **Note:** If you want to have a checkbox with an indeterminate state, you must use `TriStateCheckbox`. This is because it has a `state` parameter of type `ToggleableState`, whereas `Checkbox` does not.\n\nResult\n\nThis example produces the following component when all checkboxes are unchecked.\n**Figure 4.** Unchecked checkboxes\n\nLikewise, this is how the component appears when all options are checked, as\nwhen the user taps select all:\n**Figure 5.** Checked checkboxes\n\nWhen only one option is checked the parent checkbox display the indeterminate\nstate:\n**Figure 6.** Indeterminate checkbox\n\nAdditional resources\n\n- [Material Design Checkboxes](https://m3.material.io/components/checkbox/overview)"]]