How to determine which button pressed on android

前端 未结 5 710
闹比i
闹比i 2020-12-01 09:38

i need to know, how to recognize, which button is pressed. Like if i have two buttons ,say button 1 and button2,and both of them performing the same method, say method(),how

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 09:59

    Ok got the solution

    if (yesButton.getId() == ((Button) v).getId()){
    
      // remainingNumber
     }
    
    else if (noButton.getId() == ((Button) v).getId()) 
    {
        // it was the second button
    }
    

提交回复
热议问题