这有点奇怪。 Butterknife似乎正在使用除ViewFlipper以外的所有其他视图。我的ViewFlipper位于ListView项目上。当您点击ListView项目时,它会翻转以显示其他选项。当我使用@BindView初始化我的ViewFlipper时,这不再发生,并且应用程序没有崩溃,所以没有相关的日志。代码:
public class DepartmentListAdapter extends BaseAdapter {
Context context;
String[] departments;
@BindView(R.id.view_flipper_2) ViewFlipper flipper;
@BindView(R.id.departmentName) TextView departmentName;
@BindView(R.id.departmentOverviewButton) Button overViewButton;
@BindView(R.id.organizationalStructureButton) Button structureButton;
public DepartmentListAdapter(Context context, String[] departments){
this.context = context;
this.departments = departments;
}
@Override
public int getCount() {
return departments.length;
}
@Override
public Object getItem(int position) {
return departments[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.department_list_item, parent, false);
}else{
view = convertView;
}
ButterKnife.bind(this, view);
//this gets set
departmentName.setText(departments[position]);
flipper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//this effect is gone, not sure onClick is even being called
AnimationFactory.flipTransition(flipper, AnimationFactory.FlipDirection.TOP_BOTTOM, 90);
}
});
overViewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "DO", Toast.LENGTH_SHORT).show();
}
});
structureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "DS", Toast.LENGTH_SHORT).show();
}
});
Animation animation = AnimationUtils.loadAnimation(
context, R.anim.listview_slide);
view.startAnimation(animation);
return view;
}
}