Reputation: 765
I'm trying to have my activity respond to a single click but I cannot find a way to implement this.
I can use onTouchEvent
override that method and have my logic run there but onClick
is not possible?
What is the reason behind this and what could I do to get the desired effect that I want?
As requested: what I currently have
@Override
public void onClick(View event) {
// TODO Auto-generated method stub
x = event.getX();
y = event.getY();
pixelColor = Color.RED;
PixelParticle pp = new PixelParticle(this, x, y, 50, 50, pixelColor);
setContentView(pp);
}
this isn't working - I implement OnClickListener
and override the above method, the canvas never draws what I want it to draw.
Upvotes: 0
Views: 94
Reputation: 1879
Touch down + touch up of the same point in a short time is a onClick
(Actually onClick event in the android source code is really made in this way).
Because the onTouchEvent
(in activity) is made for you to check touch event of the whole screen.But onClick
is designed to check the click event on a view(not the whole screen).Touch event is the original event,click isn´t.
If you want to check whether your screen is clicked ,just use the onClick
method of your layout(give it an id myLayout).
LinearLayout layout = findViewById(R.id.myLayout);
layout.setOnClickListener(xxx);
Upvotes: 2