Android 检测在swipre over gridlayout中触碰的视图

Android 检测在swipre over gridlayout中触碰的视图,android,gridview,touch-event,motionevent,Android,Gridview,Touch Event,Motionevent,我目前正在开发一个应用程序,它应该能够检测gridlayout中的哪个文本视图被触摸。目标是将触摸视图的背景色设置为不同的颜色。我正在创建如下视图: for (int row = 1; row < 13; row++) { for (int col=0; col<24; col++) { TextView tv = new TextView(this); GridLayout.LayoutParams params =

我目前正在开发一个应用程序,它应该能够检测gridlayout中的哪个文本视图被触摸。目标是将触摸视图的背景色设置为不同的颜色。我正在创建如下视图:

for (int row = 1; row < 13; row++) {
        for (int col=0; col<24; col++) {
            TextView tv = new TextView(this);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(GridLayout.spec(row), GridLayout.spec(col));
            params.width = (int)(screenWidth / 24);
            params.height = (int) (tenth_heigth * 8) / 12 ;
            tv.setLayoutParams(params);
            tv.setGravity(Gravity.CENTER);
            tv.setBackgroundColor(Color.WHITE);
            tv.setText("A");
            tv.setTextAppearance(this, android.R.style.TextAppearance_Large);
            gridLayout.addView(tv, params);     
        }
    }
如果有人能给我指出正确的方向,我将不胜感激。非常感谢

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN :
                    // would like to set the background color of the touched view to blue
        break;
    case MotionEvent.ACTION_MOVE :
        // would like to set the background color of the touched views to red
        break;
    case MotionEvent.ACTION_UP :

        // set the background color to purple
        break;
    }
    return super.onTouchEvent(event);
}