In my layout xml file I have several buttons like this which share the same event handler:
<Button android:id="@+id/page1" onClick="OnClick" .... ></Button>
In my activity I would like something like this code:
public void onClick(View v) {
String url = String.format("http://example.com/%d", v.getId());
}
to dynamically build the url. However, getId() returns the integer representing the button ID, not the word “page1”.
Of course I could use a switch statement, but it would be much more convenient if I could refer to the original ID name assigned to the button.
Is that possible?
Use
getResources().getResourceName()