gpt4 book ai didi

java - Android Studio 中的文本重复器

转载 作者:行者123 更新时间:2023-12-02 10:58:10 25 4
gpt4 key购买 nike

我正在学习 Android 并正在做一个简单的文本转发器应用程序。我现在遇到一个问题。

我有这个代码

package eu.make4u.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

EditText et_input, et_output, et_number;
Button b_go;

String text ="";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

et_input = (EditText) findViewById(R.id.et_input);
et_output = (EditText) findViewById(R.id.et_output);
et_number = (EditText) findViewById(R.id.et_number);
b_go = (Button) findViewById(R.id.b_go);

b_go.setOnClickListener(new.View.OnClickListener()) {
@Override

public void onClick(View v){
String input = et_input.getText().toString();
int number = Integer.parseInt(et_number.getText().toString());

for (int i=0; i < number; i++){
text = text + input + " ";
}
et_output.setText(text);
}
});
}
}

我有 5 个错误

5 error in android studio

我正在学习这门类(class)https://www.youtube.com/watch?v=trMTw1rx30I

我找不到任何错误,有人可以帮助我吗?

最佳答案

您遇到了一些与括号相关的语法问题。已修复:

public class MainActivity extends AppCompatActivity {

EditText et_input, et_output, et_number;
Button b_go;

String text ="";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

et_input = (EditText) findViewById(R.id.et_input);
et_output = (EditText) findViewById(R.id.et_output);
et_number = (EditText) findViewById(R.id.et_number);
b_go = (Button) findViewById(R.id.b_go);

b_go.setOnClickListener(new View.OnClickListener() { //you had an extra bracket here
@Override

public void onClick(View v){
String input = et_input.getText().toString();
int number = Integer.parseInt(et_number.getText().toString());

for (int i=0; i < number; i++){
text = text + input + " ";
}
et_output.setText(text);
}
});
}
}

关于java - Android Studio 中的文本重复器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51555576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com