Get text from pressed button

前端 未结 6 1562
栀梦
栀梦 2020-12-01 03:08

How can I get the text from a pressed button? (Android)

I can get the text from a button:

String buttonText = button.getText();

I c

6条回答
  •  旧巷少年郎
    2020-12-01 04:00

    If you're sure that the OnClickListener instance is applied to a Button, then you could just cast the received view to a Button and get the text:

    public void onClick(View view){
    Button b = (Button)view;
    String text = b.getText().toString();
    }
    

提交回复
热议问题