[英]How do I change my button's Text after it is pressed in android studio?
I'm learning as I go and am trying to create a simple app. 我正在学习,正在尝试创建一个简单的应用程序。 I've run into this snag where I am setting up an event listener/callback method and want it to change the text of my button to something else. 我遇到了这个麻烦,在这里我设置了一个事件侦听器/回调方法,并希望它可以将按钮的文本更改为其他内容。
Here's a snippet of the code: 这是一段代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startButton = (TextView) findViewById(R.id.startButton);
mainMessage = (TextView) findViewById(R.id.mainMessage);
InText = (TextView) findViewById(R.id.InText);
final Button startButton = (Button)findViewById(R.id.startButton);
this.gestureDetector = new GestureDetectorCompat(this, this);
gestureDetector.setOnDoubleTapListener(this);
startButton.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
startButton = setText("change my text");
}
}
);
On the startButton = setText("change my text");
在startButton = setText("change my text");
line, I am getting the error: 行,我得到了错误:
Cannot resolve method 'setText(java.lang.String)' 无法解析方法“ setText(java.lang.String)”
Im still new to coding and understand most of the basics. 我对编码仍然很陌生,并且了解大多数基础知识。 In this same activity, I have gestures that can change the text of a textView to something else so I'm kinda stumped as to why this isn't working. 在同一活动中,我的手势可以将textView的文本更改为其他内容,因此我有点困惑为什么它不起作用。
Change 更改
startButton = setText("change my text");
to 至
startButton.setText("change my text");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.