Get text of view (button)

南笙酒味 提交于 2019-12-05 18:33:41
    public void onClick(View v) {

        Button b = (Button)v;
        String buttonText = b.getText().toString();
        Toast.makeText(getBaseContext(), buttonText , 1000).show();
    }

for example, if the View contains text, use this:

( (TextView) view ).getText().toString();

where "view" is being cast to TextView.

Do you mean you want get the text display by your button in layout file ?

You can do this by a simple

button.getText();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!