我正在边学习边尝试创建一个简单的应用程序。我在设置事件监听器/回调方法时遇到了这个问题,并希望它将按钮的文本更改为其他内容。
这是代码 fragment :
@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");
}
}
);
在 startButton = setText("change my text");
行上,我收到错误:
Cannot resolve method 'setText(java.lang.String)'
我对编码还很陌生,并且了解大部分基础知识。在同一个 Activity 中,我有一些手势可以将 textView 的文本更改为其他内容,所以我有点困惑为什么这不起作用。
最佳答案
改变
startButton = setText("change my text");
至
startButton.setText("change my text");
关于java - 在 android studio 中按下按钮后如何更改按钮的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31763621/