Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Butterknife (Easy way to Eliminate findViewById)

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 313
    Comment on it

    Remove findViewById calls by using @Bind on widgets and fields.

    Remove the click listeners by annotating methods with @OnClick and others.

        class MainActivity extends Activity {
    
          @Bind(R.id.user) EditText username;
          @Bind(R.id.pass) EditText password;
    
          @BindString(R.string.login_error)
          String loginErrorMessage;
    
          @OnClick(R.id.submit) void submit() {
            // TODO call server...
          }
    
          @Override public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.simple_activity);
            ButterKnife.bind(this);
            // TODO Use fields...
          }
        }
    
    

    For Gradle dependency

    compile 'com.jakewharton:butterknife:7.0.1'
    

    NOTE: Don't forget to use ButterKnife.bind(this) in your Oncreate.

 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: