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();
精彩评论