CopyPastor

Detecting plagiarism made easy.

Score: 0.8427836298942566; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2020-07-07
by Daniel Nyamasyo

Original Post

Original - Posted on 2018-05-24
by Tin Nguyen



            
Present in both answers; Present only in the new answer; Present only in the old answer;

do the else aftertextchanged for consistence change
private Boolean isUserInput =true; text.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { System.out.println("test "+s); if(s.length()>0 && isUserInput) { if(counter==0 && s.length()>=5) { Log.e("Edit counter 1",String.valueOf(s) ); amount[3]=s.charAt(4); } else if (counter==1&& s.length()>=5) { Log.e("Edit counter 2",String.valueOf(s) ); amount[2]=amount[3]; amount[3]=s.charAt(4); } else if (counter==2 && s.length()>=5) { amount[0]=amount[2]; amount[2]=amount[3]; amount[3]=s.charAt(4); } else { } String str = ""; for (Character c : amount) str += c.toString(); System.out.println("Edit test "+str); text.setText(str); isUserInput = false; } counter++; } @Override public void afterTextChanged(Editable s) { isUserInput = true; }
When you call
text.setText(str);
inside `onTextChanged ` callback, that TextView will change text one more time, then `onTextChanged` will be called again. It will cause an infinite loop there.
**edit:**
You can add a bool flag for this case. Ex: `isUserInput`.
text.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { System.out.println("test "+s); if(s.length()>0 && isUserInput) {
if(counter==0 && s.length()>=5) { Log.e("Edit counter 1",String.valueOf(s) ); amount[3]=s.charAt(4); } else if (counter==1&& s.length()>=5) { Log.e("Edit counter 2",String.valueOf(s) ); amount[2]=amount[3]; amount[3]=s.charAt(4); } else if (counter==2 && s.length()>=5) { amount[0]=amount[2]; amount[2]=amount[3]; amount[3]=s.charAt(4); } else {
}

String str = "";
for (Character c : amount) str += c.toString();
System.out.println("Edit test "+str);

text.setText(str); isUserInput = false; }else{ isUserInput = true; } counter++;
}

        
Present in both answers; Present only in the new answer; Present only in the old answer;