onTouchEvent in a BaseAdapter Android

有些话、适合烂在心里 提交于 2019-12-13 04:37:47

问题


In my program I must insert this onTouchEvent method in a BaseAdapter component:

    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;
}

This function works in an Activity (it's right) but in this component it's not works. I think that the problem is that the layoutComments is inserted in a ViewHolder, but I can't pass the view to the onTouchEvent. Any ideas?


回答1:


Follow Like this:

 public class YourClassName extends Activity
{

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

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

Hope this will help you.



来源:https://stackoverflow.com/questions/17401603/ontouchevent-in-a-baseadapter-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!