richeditor-android
richeditor-android copied to clipboard
How can I get the 'pure' text without any formatting from the editor? (如何获取不带格式的Text?)
I want to get the 'pure' text but not the html from the editor. How can I get it? I want to judge the length of the text.
Thanks~:D
Here is my code. But I can't get the callBack when the sdk < KITKAT.
/**
* The valueCallback is disposable,
* so we need to put this method into the implement of OnTextChangeListener.
* 这个回调是一次性的, 所以需要在 OnTextChangeListener 的实现方法里面调用此方法。
*/
public void loadContentTextChangeListener() {
loadCode("javascript:RE.getText();", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
// The value text is within double quotation.
// So we should deal with it and only return the text except the double quotation.
// 返回的Value里面默认有双引号, 所以要进行相关处理除去双引号
String text = value != null ? value.substring(1, value.length() - 1) : null;
if (onContentTextChangeListener != null) {
onContentTextChangeListener.onContentTextChange(text);
}
}
});
}
private void loadCode(String JSCode, ValueCallback<String> valueCallback) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
evaluateJavascript(JSCode, valueCallback);
} else {
loadUrl(JSCode);
}
}
Document doc = Jsoup.parse(mEditor.getHtml()); String txt = doc.body().text();
@zhangxi28 it's work for me,thx!
other attention :
add this:
dependencies { compile 'org.jsoup:jsoup:1.9.2' }
Awesome!!!
@zhangxi28 it's work for me,thx! other attention : add this:
dependencies { compile 'org.jsoup:jsoup:1.9.2' }