原因解析:
include 引入了一个布局
如果想拿到这个布局中的某个id对应的控件,应当这样拿
// 获取到这个布局
View view = LayoutInflater.from(context).inflate(R.layout.view_custom_textview,this);
// 获取某个id对应的控件
View view = view.findviewbyid(R.id.custom_textview_image);
解决方案:(类似viewhold)
// 关键是 ButterKnife.bind(this,view);
public class KapCustomTextView extends FrameLayout {
@BindView(R.id.custom_textview_image)
ImageView imageView;
@BindView(R.id.custom_textview_edittext)
EditText editText;
public KapCustomTextView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
View view = LayoutInflater.from(context).inflate(R.layout.view_custom_textview,this);
ButterKnife.bind(this,view);
}
public ImageView getImageView() {
return imageView;
}
public EditText getEditText() {
return editText;
}
}
网友评论