开发者

onClick and onTouch on TextView?

开发者 https://www.devze.com 2023-02-13 03:20 出处:网络
I want to do something when the user touch (or click) on a TextView but I can\'t seems to make it work.

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

精彩评论

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