Android - TableLayout中的基本手势检测

时间:2014-04-20 09:51:10

标签: android listener gesture-recognition

我是Android开发的新手,所以请原谅这篇文章的天真。我有一个表格布局,我在其中动态地为每个单元格添加文本视图。我希望在细胞上添加一个滑动检测,并根据刷过的细胞执行操作。我尝试在每个单元格上添加onSwipeTouchListener。

TextView txtviewCell = new TextView(getActivity());
TableRow.LayoutParams paramsExample = new TableRow.LayoutParams(60, 60);
txtviewCell.setBackgroundColor(0xfffaf8ef);
txtviewCell.setGravity(Gravity.CENTER);
paramsExample.setMargins(5, 5, 5, 5);
txtviewCell.setLayoutParams(paramsExample);
final int currRow = i;
final int currCol = j;
txtviewCell.setOnTouchListener(new OnSwipeTouchListener(
        getActivity()) {
    public void onSwipeTop() {
        handleSwipe(currRow, currCol);
    }

    public void onSwipeRight() {
        handleSwipe(currRow, currCol);
    }

    public void onSwipeLeft() {
        handleSwipe(currRow, currCol);
    }

    public void onSwipeBottom() {
        handleSwipe(currRow, currCol);
    }

    public boolean onTouch(View v, MotionEvent event) {
        return gestureDetector.onTouchEvent(event);
    }
});
allCells[i][j] = txtviewCell;

现在,当我轻扫时,我在onSwipe函数中获得控件,但是我没有得到正确的行号和列号。是否有特定的方法在文本视图上附加滑动事件并获取该单元格的行号和列号?

1 个答案:

答案 0 :(得分:0)

我猜每个textview都有不同的ID,所以尝试获取id并使用它来控制流程。