得到pressed按钮上的文字 [英] get text from pressed button
本文介绍了得到pressed按钮上的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能从pressed按钮上的文本? (安卓)
我可以从一个按钮上的文本:
字符串buttonText = button.getText();
我可以从pressed按钮的ID:
INT buttinID = view.getId();
我找不到什么了,在这一刻是如何获得的pressed按钮上的文本。
公共无效的onClick(视图查看){
//获取在pressed按钮上的文本
}
解决方案
你得到的传递的视图的onClick()
是您正在寻找的按钮。
公共无效的onClick(视图v){
// 1)可能检查的第一实例
按钮B =(按钮)V;
字符串buttonText = b.getText()的toString()。
}
1)如果您是使用非匿名类 onClickListener
,你可能要检查的
类型转换它,因为它可能是一些比按钮之前不同的看法。
How can I get the text from a pressed button? (Android)
I can get the text from a button:
String buttonText = button.getText();
I can get the id from a pressed button:
int buttinID = view.getId();
What I can't find out at this moment is how to get the text on the pressed button.
public void onClick(View view) {
// Get the text on the pressed button
}
解决方案
The view you get passed in on onClick()
is the Button you are looking for.
public void onClick(View v) {
// 1) Possibly check for instance of first
Button b = (Button)v;
String buttonText = b.getText().toString();
}
1) If you are using a non-anonymous class as onClickListener
, you may want to check for the
type of the view before casting it, as it may be something different than a Button.
这篇关于得到pressed按钮上的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文