0

在我的程序中,我必须在 BaseAdapter 组件中插入这个 onTouchEvent 方法:

    public class FlipAdapter extends BaseAdapter {

        ...           
    public boolean onTouchEvent(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;
}

此功能在 Activity 中有效(正确),但在此组件中无效。我认为问题在于 layoutComments 被插入到 ViewHolder 中,但我无法将视图传递给 onTouchEvent。有任何想法吗?

4

1 回答 1

0

像这样关注:

 public class YourClassName extends Activity
{

   @Override
     protected void onCreate(Bundle savedInstanceState) 
       {
        .......
        } 

    class FlipAdapter extends BaseAdapter
    {
            //Now you can access everything from the activity.
    } 
 } 

希望这会帮助你。

于 2013-07-01T10:00:02.810 回答