我有一个实现 OnTouchListener 类的 BaseAdapter。onTouch 方法是:
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
startY = event.getY();
break;
}
case MotionEvent.ACTION_UP: {
float endY = event.getY();
if (endY > startY) {
layoutComments.startAnimation(animDown);
layoutComments.setVisibility(View.GONE);
}
}
}
return true;
}
问题在于 layoutComments 变量被插入到 getView 方法中声明的 ViewHolder 中:
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
...
...
程序无法查看变量,有两个编译器错误。如何从 onTouch 的变量 v 中获取 ViewHolder?