【发布时间】:2023-04-09 00:10:01
【问题描述】:
我是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 函数中获得了控件,但我没有获得正确的行号和列号。是否有特定的方法可以在 textview 上附加滑动事件并获取该单元格的行号和列号?
【问题讨论】:
标签: android listener gesture-recognition