از Kotlin synthetics به Jetpack view binding مهاجرت کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برنامه افزودنی اندروید Kotlin منسوخ شده است، به این معنی که استفاده از ترکیب مصنوعی Kotlin برای اتصال مشاهده دیگر پشتیبانی نمی شود. اگر برنامه شما از مواد مصنوعی Kotlin برای اتصال به نمایش استفاده می کند، از این راهنما برای انتقال به جت پک نمای صحافی استفاده کنید.
اگر برنامه شما قبلاً از ترکیبات مصنوعی Kotlin برای اتصال مشاهده استفاده نمیکند، برای اطلاعات اولیه استفاده، به View binding مراجعه کنید.
فایل Gradle را به روز کنید
مانند برنامههای افزودنی اندروید، جتپک نمای جت بر اساس ماژول به ماژول فعال میشود. برای هر ماژولی که از view binding استفاده می کند، گزینه ساخت viewBinding را در فایل build.gradle سطح ماژول روی true تنظیم کنید:
شیار
android{...buildFeatures{viewBindingtrue}}
کاتلین
android{...buildFeatures{viewBinding=true}}
اگر برنامه شما از ویژگیهای Parcelable استفاده نمیکند، خطی را که برنامههای افزودنی اندروید Kotlin را فعال میکند حذف کنید:
شیار
plugins{id'kotlin-android-extensions'}
کاتلین
plugins{kotlin("android.extensions")}
برای کسب اطلاعات بیشتر در مورد فعال کردن اتصال مشاهده در یک ماژول، به دستورالعملهای راهاندازی مراجعه کنید.
به روز رسانی فعالیت و کلاس های قطعه
با Jetpack view binding، یک کلاس binding برای هر فایل طرح بندی XML که ماژول حاوی آن است، تولید می شود. نام این کلاس binding نام فایل XML در حروف پاسکال است که در انتهای آن کلمه Binding اضافه شده است. برای مثال، اگر نام فایل layout result_profile.xml باشد، نام کلاس binding تولید شده ResultProfileBinding است.
برای استفاده از کلاسهای binding تولید شده به جای ویژگیهای مصنوعی برای ارجاع نماها، کلاسهای Activity و Fragment خود را با انجام کارهای زیر تغییر دهید:
تمام موارد وارداتی را از kotlinx.android.synthetic حذف کنید.
یک نمونه از کلاس اتصال تولید شده را برای استفاده از اکتیویتی یا قطعه ایجاد کنید.
همه مراجع مشاهده را تغییر دهید تا از نمونه کلاس binding به جای ویژگی های مصنوعی استفاده کنید:
// Reference to "name" TextView using synthetic properties.name.text=viewModel.nameString// Reference to "name" TextView using the binding class instance.binding.name.text=viewModel.nameString
برای کسب اطلاعات بیشتر، بخش استفاده را در راهنمای اتصال مشاهده ببینید.
{% کلمه به کلمه %} {% آخر کلمه %}
برای شما توصیه می شود
توجه: وقتی جاوا اسکریپت خاموش است، متن پیوند نمایش داده می شود
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Migrate from Kotlin synthetics to Jetpack view binding\n\nKotlin Android Extensions is deprecated, which means that using Kotlin\nsynthetics for view binding is no longer supported. If your app uses Kotlin\nsynthetics for view binding, use this guide to migrate to Jetpack view binding.\n\nIf your app doesn't already use Kotlin synthetics for view binding, see [View\nbinding](/topic/libraries/view-binding) for basic usage information.\n\nUpdate the Gradle file\n----------------------\n\nLike Android Extensions, Jetpack view binding is enabled on a module-by-module\nbasis. For each module that uses view binding, set the `viewBinding` build\noption to `true` in the module-level `build.gradle` file: \n\n### Groovy\n\n```groovy\nandroid {\n ...\n buildFeatures {\n viewBinding true\n }\n}\n```\n\n### Kotlin\n\n```kotlin\nandroid {\n ...\n buildFeatures {\n viewBinding = true\n }\n}\n```\n\nIf your app doesn't use [`Parcelable`](/reference/android/os/Parcelable)\nfeatures, remove the line that enables Kotlin Android Extensions: \n\n### Groovy\n\n```groovy\nplugins {\n id 'kotlin-android-extensions'\n}\n```\n\n### Kotlin\n\n```kotlin\nplugins {\n kotlin(\"android.extensions\")\n}\n```\n| **Note:** If your app uses `Parcelable` features, switch to using the standalone `kotlin-parcelize` Gradle plugin described in [Parcelable implementation generator](/kotlin/parcelize).\n\nTo learn more about enabling view binding in a module, see [Setup\ninstructions](/topic/libraries/view-binding#setup).\n\nUpdate activity and fragment classes\n------------------------------------\n\nWith Jetpack view binding, a binding class is generated for each XML layout file\nthat the module contains. The name of this binding class is the name of the XML\nfile in Pascal case with the word *Binding* added at the end. For example, if\nthe name of the layout file is `result_profile.xml`, the name of the generated\nbinding class is `ResultProfileBinding`.\n\nTo use the generated binding classes instead of synthetic properties to\nreference views, change your activity and fragment classes by doing the\nfollowing:\n\n1. Remove all imports from `kotlinx.android.synthetic`.\n\n2. Inflate an instance of the generated binding class for the activity or\n fragment to use.\n\n - For activities, follow the instructions in [Use view binding in\n activities](/topic/libraries/view-binding#activities) to inflate an instance in your activity's [`onCreate()`](/reference/kotlin/android/app/Activity#oncreate) method.\n - For fragments, follow the instructions in [Use view binding in\n fragments](/topic/libraries/view-binding#fragments) to inflate an instance in your fragment's [`onCreateView()`](/reference/kotlin/androidx/fragment/app/Fragment#oncreateview) method.\n3. Change all view references to use the binding class instance instead of\n synthetic properties:\n\n // Reference to \"name\" TextView using synthetic properties.\n name.text = viewModel.nameString\n\n // Reference to \"name\" TextView using the binding class instance.\n binding.name.text = viewModel.nameString\n\nTo learn more, see the [Usage](/topic/libraries/view-binding#usage) section in\nthe view binding guide.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [View binding](/topic/libraries/view-binding)\n- [Paging library overview](/topic/libraries/architecture/paging/v3-overview)\n- [Test your Paging implementation](/topic/libraries/architecture/paging/test)"]]