![](/img/trans.png)
[英]Textview changing according to spinner and edittext with button click
[英]Changing textview on edittext ( when possible without a button)
我对Android的Java编程有点陌生,所以如果我犯了愚蠢的错误,对不起。
因此,基本上,我要制作一个应用程序,如果您正确输入答案,将显示下一个文本视图。 当下一个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")
我真的很困,我希望你们想帮助我。
如果要更改不带按钮的视图,则可以使用addTextChangeListner()方法,该方法将在特定编辑文本的文本更改时通知您。
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());
}
}
};
int x=0; //to keep track of qustions
private List<String> mQuestionList=new ArrayList<>(); //array of question
private List<String> mAnswerList=new ArrayList<>(); //array of question answer
displayquestion.settext(mQuestionList.get(x);//displayquestion is textview
//nextquestion is the button when user click it will first check answer and than move to next question if answer is correct
nextquestion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String answer=editText.getText().toString();
if(answer.equal(mAnswerList.get(x)){
x=x+1;
displayquestion.settext(mQuestionList.get(x); //answer is correct display next quesion
}else{
//wrong answer
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.