Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 浓缩咖啡测试:刷卡操作不会触发右触事件序列_Android_Touch Event_Android Espresso - Fatal编程技术网

Android 浓缩咖啡测试:刷卡操作不会触发右触事件序列

Android 浓缩咖啡测试:刷卡操作不会触发右触事件序列,android,touch-event,android-espresso,Android,Touch Event,Android Espresso,我正在编写一个应用程序来模拟粘性标题功能,当listview向上滚动时,标题将被隐藏并导航。酒吧将坚持到顶部。我在IntercepteTouchEvent和onScrollListener上实现了一个自定义listview并覆盖dispatchTouchEvent。因此,我的listview的代码是: public class MyListView extends ListView { private ObservableScrollViewCallbacks mCallbacks; priva

我正在编写一个应用程序来模拟粘性标题功能,当listview向上滚动时,标题将被隐藏并导航。酒吧将坚持到顶部。我在IntercepteTouchEvent和onScrollListener上实现了一个自定义listview并覆盖dispatchTouchEvent。因此,我的listview的代码是:

public class MyListView extends ListView {
private ObservableScrollViewCallbacks mCallbacks;
private boolean mIsFlingEnded = true;
private OnScrollListener mScrollListener = new OnScrollListener() {
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        mIsFlingEnded = scrollState == SCROLL_STATE_IDLE;
        if (mCallbacks != null) {
            mCallbacks.onScrollChanged(mScrollY, mOnDragging, mIsFlingEnded);
        }
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        onScrollChanged();   // calculate scrolled offset
    }
};

public StickyHeaderObservableListView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

private void init() {
    this.setOnScrollListener(mScrollListener);
    mListViewItemHeights = new SparseIntArray();
}

public interface ObservableScrollViewCallbacks {
    public void onScrollChanged(int scrollY, boolean dragging, boolean isFlingEnded);

    public void onDownMotionEvent();

    public void onMoveEnded(boolean isFlingEnded);
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    int actions = event.getAction();
    if (mCallbacks != null) {
        if (actions == MotionEvent.ACTION_UP || actions == MotionEvent.ACTION_CANCEL) {
            mOnDragging = false;
            mCallbacks.onMoveEnded(mIsFlingEnded);
        }
    }
    return super.dispatchTouchEvent(event);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (mCallbacks != null) {
        final float y = event.getY();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mCallbacks.onDownMotionEvent();
                break;
            case MotionEvent.ACTION_MOVE:
                mOnDragging = true;
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mOnDragging = false;
                break;
        }
    }
    return super.onInterceptTouchEvent(event);
}
现在,我正在listview上编写一个测试,以便向上滑动。swipeUp方法的实现方式与espresso源代码的swipeLeft或swipeRight类似:

swipeUp代码

public static ViewAction swipeUp() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER,
    GeneralLocation.TOP_CENTER, Press.FINGER); }
这个方法很好用,我的意思是listview可以向上滚动,但是标题的位置不会改变。原因是在onScrollChanged()之后调用dispatchTouchEvent和onInterceptTouchEvent。这是不对的。 因此,当我用手指滚动listview时,效果非常好,正确的触摸事件顺序是:dispatchTouchEvent()->onInterceptTouchEvent()->onScrollChanged()->onScrollStateChanged()

我的第一个想法是,这种swipeUp方法可能不正确,我们是否有其他方法可以使用这种swipeUp

谢谢

更新:

在这里找到了解决方案,我使用的是Espresso 2.0,当使用onData、atPosition()时,它会导致listview滚动到顶部。 链接此处