我是 android java 编程的新手,所以如果我犯了愚蠢的错误,我很抱歉。
基本上,我想做的是一个应用程序,如果您正确输入答案,就会显示下一个 TextView 。当显示下一个 textView 时,您需要在正确给出答案时给出该 textView 的答案。 TextView 再次更改。等等。
有人知道如何做到这一点吗?
如果你不明白我在说什么,这里有一个例子:
public class Game extends AppCompatActivity {
public static EditText editText_ans;
public static TextView textView_1;
String enteredText = editText.getText().toString();
If(enteredText = 3 && textView_1 = @string/1+2){
setText.textView_1(@string/3+4)
}
If(enteredText = 7 && textView_1 = @string/3+4){
setText.textView_1("100 - 23")
我真的被困住了,我希望你们愿意帮助我。
最佳答案
如果您想在没有按钮的情况下更改 View ,您可以使用 addTextChangedListener() 方法,该方法会在特定编辑文本的文本发生更改时通知您。
edittext.addTextChangedListener(textWatcher);
private final TextWatcher textWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
textView.setVisibility(View.VISIBLE);
}
public void afterTextChanged(Editable s) {
if (s.length() == 0) {
textView.setVisibility(View.GONE);
} else{
textView.setText("You have entered : " + editText.getText());
}
}
};
关于java - 更改 edittext 上的 textview(如果可能没有按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34705797/