开发者

onClick and onTouch on TextView?

I want to do something when the user touch (or click) on a TextView but I can't seems to make it work.

I simply place a TextView in Layout and 开发者_Go百科I tryied to set an onclick listener.

        touchTV = (TextView) findViewById(R.id.touchTV);
    touchTV.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v)
                {
                Toast.makeText(getApplicationContext(), "Text Touch",
                        Toast.LENGTH_SHORT);
                }
        });

But nothing happen when I click on the TextView.

I tryied the same thing but with an onTouch listener but I get the same (lack of) result.


You forgot to call show() on the Toast and so it was never displayed; its a common mistake :-) Change code to:

Toast.makeText(getApplicationContext(),"Text Touch",Toast.LENGTH_SHORT).show();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜