2016-01-10 27 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

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

相關問題