Prasanna
Prasanna

Reputation: 2661

Getting text from a button

If I use multiple ids with same @Click event method like

@ViewById Button choice1;
@ViewById Button choice2;

    @Click({R.id.choice1,R.id.choice2})
    void choice(){
        //String text = text of the clicked button
    }

How will I get the text of the button that is being clicked?

Upvotes: 0

Views: 54

Answers (1)

DayS
DayS

Reputation: 1561

As wrote on the wiki you can add a View parameter in your method signature, like this :

@Click({R.id.choice1, R.id.choice2})
void choice(View clickedView) {
    [...]
}

Also you don't have to annotate your buttons with ViewById in order to use Click (unless you really need a reference to these instances, of course)

Upvotes: 1

Related Questions