您可以使用该android:id=@+id/buttonX值来确定按下了哪个按钮。
在您的活动代码中(可能)是这样的:
private int mButtonPressed = -1;
... heap of code ...
public void pressedButton(View view) {
mButtonPressed = view.getId();
}
// your code from your question
if (mButtonPressed == R.id.buttonX) {
return result to start time TextView;
} else if (mButtonPressed == R.id.buttonY) {
return result to end time TextView;
}
在按钮的布局 XML 中,确保包括:
<Button
android:id="@+id/buttonX"
android:onclick="pressedButton"
... more attributes ...
/>
<Button
android:id="@+id/buttonY"
android:onclick="pressedButton"
... more attributes ...
/>