I’m assigning a button listener to multiple buttons like so:
for(Button b : buttons)
{
b.setOnClickListener(clicklisten);
}
The button listener is defined as follows:
private OnClickListener clicklisten = new OnClickListener()
{
public void onClick(View v)
{
Context context = getApplicationContext();
text = Toast.makeText(context, " Button Clicked", Toast.LENGTH_SHORT);
text.show();
}
};
As it is, it just shows a Toast with “Button Clicked” displaying. I’d like it to detect which button is clicked, perhaps via the name or ID of that button (as defined in the XML), and display something based on that. Is it possible to retrieve that information through the code this way?
Get the resource id by View#getId().