You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, my name is Eduardo and i have been trying to figure out a way to set a onClickListener on a PhysicsLayout child view to change its background color. The thing is, when i do, all the physics behaviour stop working. Do you have any suggestions that could help me?
Sorry if this is a obvious question, i am just starting android developing :P
The text was updated successfully, but these errors were encountered:
edunuzzi
changed the title
Help with onClickListener on PhysicsLayout child
Help with onClickListener on PhysicsLayout child view
Aug 23, 2015
Hi,
i had the same problem. The onClickListener is obliviously interfering with the touchListener of the library, so i guess you can't have both. Fortunately you can use the touchInterface provided by the PhysicsLayout library. Just use the "touchEvents" to identify a click yourself. One way could be to track the time difference the user grabbed and released an item. If its shorter than a certain threshold its considered a click. To improve this you could also track the position of the grab and release and if it exceeds a certain distance its not a click anymore. I hope this helps.
physicsRelativeLayout.getPhysics().setOnFlingListener(new Physics.OnFlingListener() {
private static final int clickTimeDeltaInMs = 150;
private long grabStarTime = 0;
@Override
public void onGrabbed(View view) {
grabStarTime = Calendar.getInstance().getTimeInMillis();
}
@Override
public void onReleased(View view) {
final long grabReleaseTime = Calendar.getInstance().getTimeInMillis();
if((grabReleaseTime - grabStarTime) > clickTimeDeltaInMs) {
System.out.println("no click");
return;
}
//do stuff – its a click
}
});
Hi, my name is Eduardo and i have been trying to figure out a way to set a onClickListener on a PhysicsLayout child view to change its background color. The thing is, when i do, all the physics behaviour stop working. Do you have any suggestions that could help me?
Sorry if this is a obvious question, i am just starting android developing :P
The text was updated successfully, but these errors were encountered: