Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use Butterknife in Android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 307
    Comment on it

    ButterKnife is library to initialize the views with Annotations.
    With the help of Butterknife you have no need to initialize view with findViewBtId().

    here we start.

    1. Create Project.

    2. Open module level build.gradle file.

    3. Add below dependencies.

    compile 'com.jakewharton:butterknife:8.3.0'

    4. Open your Activity and add below line in onCreate() after setContentView.

    ButterKnife.bind(this);

    5. onCreate() look like:-

    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
     
      }
    }

    6. Create Field variable of view with annotation @BindView(ID_OF_VIEW). 

     @BindView(R.id.my_textview) 
    TextView title;
      @BindView(R.id.my_button)
    Button subtitle;

     

    ButterKnife is very helpful when you have very complex design.

     

    Happy Coding :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: