2016-01-10 20 views
1

改变TextView的我有点新的Java编程的Android,所以如果我做愚蠢的错误,我很抱歉。上的EditText(如果可能的话没有一个按钮)

所以基本上,我想提出的是:如果你的答案正确输入时,将要显示的下一个TextView的应用程序。当显示下一个textView时,当正确给出答案时,您需要给出该textView的答案。 textview再次改变。等等。

有谁有一个想法如何做到这一点?

如果你不undarstand什么即时消息说,这里是一个例子:

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") 

我很坚持,我希望你们想帮助我。

+0

意味着与回答一个问题,如果用户键入正确的答案将其移动到下一个问题 –

+0

是的,我真的dont't知道该怎么做! @YounasBangash –

+0

做你有解决方案或不 –

回答

0
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 
      } 
     } 
    }); 
+1

非常感谢你!!!!我真的很感激! –

2

如果你想改变视图,而不按钮,您可以使用方法addTextChangeListner(),它会通知您何时当文本hasbeen改变特定的EditText。

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()); 
      } 
     } 
    }; 
+0

我会改变'editText.getText()''到s.toString()',是因为我喜欢明确的关于我的'的toString()'调用。否则,很好的答案。 – MeetTitan

+0

如果它帮助你接受的答案,以便它帮助其他用户 –

相关问题