android click事件中获取 Button文本 从一个按钮开关中获取文本

android获取Button文本 从一个按钮开关中获取文本

在程序里可以从一个按钮中获取文本
String buttonText = button.getText();
也可以从按钮开关中获取id
int buttinID = view.getId();
但是如何从按钮开关中获取文本呢?这俩个怎么结合呢?
在onClick()中传递的视图就是你要找的button,需要强制转换一下。
public void onClick(View view) {
// 从按钮开关中获取文本
Button b = (Button)v;
String buttonText = b.getText().toString();
}

作者: 执着小钟

执着小钟

《android click事件中获取 Button文本 从一个按钮开关中获取文本》有3个想法

  1. Seegatesite continued on introduction android programming tutorial that I have discussed in previous articles, this time I will share android programming tutorial on how the button to switch between activity to another activity. In developing Android App we may be facing a situation where we need to move between the Activity (Screen) to another activity. Before further discussion, I will explain a little bit about the activity on android. Each activity always begins with a callback method onCreate (). Sequence callback method from start activity until the end of the activity can be seen in the following diagram lifecycle activity below

发表评论