editContent.addTextChangedListener(new TextWatcher() {
private CharSequence temp;
private int editStart, editEnd;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
temp = s;
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable s) {
editStart = editContent.getSelectionStart();
editEnd = editContent.getSelectionEnd();
int mCount = 500 - temp.length();
textCount.setText("" + mCount);
if(temp.length() > 500){
BdhShop.getInstance().getToast().show("评论内容已达最大长度!");
s.delete(editStart-1, editEnd);
int tempSelection = editStart;
editContent.setText(s);
editContent.setSelection(tempSelection);
}
}
});