ide/androidstudio

com.jakewharton:butterknife:8.4.0 @BindView 에러

C/H 2016. 12. 22. 08:30

com.jakewharton:butterknife:8.4.0 @BindView 에러

dependencies {
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.jakewharton:butterknife-compiler:8.4.0' // compile을 같이 등록해야 한다.
//    compile 'com.jakewharton:butterknife-annotations:8.4.0'
//    compile 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
}


import butterknife.*;

// Activity
super.setContentView(layoutResID);
ButterKnife.bind(this);

//  Fragment
View  view = LayoutInflater.from(getActivity()).inflate(resId, null);
ButterKnife.inject(this, view);

// Bind
@BindView(R.id.view_action) View view_action;
@BindView(R.id.textView) Textview textView;

@BindString(R.string.title) String title;
@BindBool(R.bool.isTed) boolean isTed;
@BindInt(R.integer.myinteger) int myinteger;
@BindDrawable(R.drawable.graphic) Drawable graphic;
@BindColor(R.color.red) int red;
@BindDimen(R.dimen.spacer) Float spacer;
@BindDimen(R.dimen.intvalue) int intvalue;

// LISTENER BINDING
@OnClick(R.id.submit)
public void submit(View view) {
  // TODO submit data to server...
}

@OnClick(R.id.submit)
public void submit() {
  // TODO submit data to server...
}

@OnClick(R.id.submit)
public void sayHi(Button button) {
  button.setText("Hello!");
}

@OnClick({ R.id.door1, R.id.door2, R.id.door3 })
public void pickDoor(DoorView door) {
  if (door.hasPrizeBehind()) {
    Toast.makeText(this, "You win!", LENGTH_SHORT).show();
  } else {
    Toast.makeText(this, "Try again", LENGTH_SHORT).show();
  }
}

public class FancyButton extends Button {
  @OnClick
  public void onClick() {
    // TODO do something!
  }
}

// Hoder
public class MyAdapter extends BaseAdapter {
  @Override public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    if (view != null) {
      holder = (ViewHolder) view.getTag();
    } else {
      view = inflater.inflate(R.layout.whatever, parent, false);
      holder = new ViewHolder(view);
      view.setTag(holder);
    }

    holder.name.setText("John Doe");
    // etc...

    return view;
  }

  static class ViewHolder {
    @BindView(R.id.title) TextView name;
    @BindView(R.id.job_title) TextView jobTitle;

    public ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}


GitHub

buildscript {
  repositories {
    mavenCentral()
   }
  dependencies {
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
  }
}

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

dependencies {
  compile 'com.jakewharton:butterknife:8.4.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}
반응형

'ide > androidstudio' 카테고리의 다른 글

Android Networking Connect  (0) 2016.12.27
현재 메소드 명  (0) 2016.12.23
rxAndroid rxlifecycle RetroLambda, Lambda Error  (0) 2016.12.21
rxAndroid rxlifecycle prepareDebugAndroidTestDependencies Error  (0) 2016.12.20
buildInfoDebugLoader  (0) 2016.12.19