在Kotlin下使用ButterKnife框架

Android jar 包

compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
代码
@BindView(R.id.tv_regist_trade)
TextView tv_regist_trade;
@BindView(R.id.ll_trade_all)
LinearLayout llTrade;
View mContextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
 
  
   mContextView = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
 
  
   setContentView(mContextView);   
//初始化控件

   ButterKnife.bind(this);
	
}
 
  
@Override
protected void onDestroy() {
  //接触绑定
   ButterKnife.bind(this, mContextView).unbind();
  
   super.onDestroy();
}

kotlin jar 包 

 
  
compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}
 
  
代码 
val tv_regist_trade: TextView  by bindView(R.id.tv_regist_trade)
val llTrade: LinearLayout by bindView(R.id.ll_trade_all)
 
  
/**当前Activity渲染的视图View**/
var mContextView: View? = null

 
  
   override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mContextView = LayoutInflater.from(this).inflate(R.layout.activity_main, null)

        super.setContentView(mContextView)
}



你可能感兴趣的:(android,kotlin)