![]() 2. Using the Butter Knife Library with List ViewsĬlass is a special case to implement, because you instantiate the views inside an adapter. #Butter knife toast android studio how to#That is all you have to do to use the Butter Knife library in an activity or fragment.In the next section, I’ll show you how to use the Butter Knife library for using list views. ![]() Butter Knife will handle the instantiation of every single view for you. You can now start using the views in your application’s code. View view = inflater.inflate(R.layout.sample_fragment, null) ButterKnife.inject(this, view) If you are using fragments, you have to specify the source of the views in the onCreateView() Method of the activity, before using any the views TextView sample_textview Step 3: Inject Views Method and add before the declaration of the variable, indicating the identifier of the view. In every activity or fragment, you have to remove, or comment out, every call of the findViewById() Next, synchronize your project with this file by pressing the synchronize button. Using the Butter Knife Library Step 1: Add the DependencyĪdd the following dependency to the project’sįile: compile 'com.jakewharton:butterknife:6.1.0' Let’s explore the steps involved to integrate the Butter Knife library. ![]() In the sample project of this tutorial, you can see a sample application with one activity and one fragment with an implementation using the Butter Knife library and a regular implementation. It also has annotations to handle events like onClick(), onLongClick(), etc. The Butter Knife library, developer and maintained by Jake Wharton (Square Inc.), has annotations that help developers to instantiate the views from our activity or fragment. ![]() But as applications’ designs get more complex layouts, the call to this method becomes repetitive and this is where the Butter Knife library comes in. Method for each view in the layout that you want to use in your application’s code. In every Android application, you have to use the findViewById() In this quick uang lelah, you’ll learn how to integrate the Butter Knife library in your projects to easily instantiate the views in your layout in your application’s code. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |