如何从按下的按钮获取文本? (安卓)
我可以从按钮获取文本:
String buttonText = button.getText();
我可以从按下的按钮获取 id:
int buttinID = view.getId();
目前我不知道如何获取按下的按钮上的文本。
public void onClick(View view) {
// Get the text on the pressed button
}
您传递的视图onClick()
是您正在寻找的按钮。
public void onClick(View v) {
// 1) Possibly check for instance of first
Button b = (Button)v;
String buttonText = b.getText().toString();
}
1)如果您使用非匿名类作为onClickListener
,您可能需要检查
在投射视图之前确定视图的类型,因为它可能与按钮不同。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)