textview中的ontouchlisteners

时间:2011-02-25 07:42:15

标签: java android

我正在尝试在我拥有的每个文本视图中实现ontouchlistener,这样当我触摸textview时它会发生振动

但是我有这个问题“无法降低view.ontouchlistener中继承方法的可见性”

任何人都知道我做错了什么?我已经实现了OnTouchListener

        for (int i = 0; i < counter; i++)
        {
                tv[i] = new TextView(this);
                tv[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
                tv[i].setTextSize(textSize);
                tv[i].setText(""+singleText[i]);
                tv[i].setOnTouchListener(this);
                linearLayout.addView(tv[i]);
        }
        setContentView(linearLayout);

    }
    catch (IOException e) {
        //You'll need to add proper error handling here
    }       
}

private boolean onTouch(View v, MotionEvent event)
{
    vibratePattern();
    return true;
}

1 个答案:

答案 0 :(得分:2)

只需将此onTouch()方法设为公开

即可
public boolean onTouch(View v, MotionEvent event)
{
    vibratePattern();
    return true;
}