Ketan Ahir
Ketan Ahir

Reputation: 6738

Identify manual and programatically button click

In my app I have one button which works as "pause" and "Resume". Here user can click this button manually to pause and resume. And somethimes I am performing click programatically using view.performClick() method.

The question is....is it possible to know by which click button clicked ?

Thanks

Edit:

I am using timer in my app and I want to pause and resume timer.

Upvotes: 0

Views: 181

Answers (3)

Manmeet Singh Batra
Manmeet Singh Batra

Reputation: 467

if(button.getText().toString().trim().equalsIgnoreCase("pause")){
// puse your timer here or whatever you would like

}else{
//resume your time here or whatever you would like
}

Upvotes: 0

Daniel Fekete
Daniel Fekete

Reputation: 5028

Handle the click in a different method:

private void handleClick(boolean manualClick) {
    //your code...
}

public void onClick(View view) {
    handleClick(true);
}

and do not use view.performClick() to call it automaically, but call handleClick(false)

Upvotes: 2

Manish Lomte
Manish Lomte

Reputation: 329

You can set the flag true/false when click manually, and use that while performing click operation.

Upvotes: 0

Related Questions