下面的代码有效,但感觉不干净。对getSelectionEnd()的调用需要在Runnable中完成,否则performFiltering将在它有值之前触发。问题是我需要调用重写的超级函数performFiltering,我唯一能想到的方法是创建一个只用于调用超级函数的愚蠢函数,参见" superFiltering&#34 ;。我怎样才能让这个更干净?
@Override
protected void performFiltering(final CharSequence text, final int keyCode) {
post(new Runnable() {
@Override
public void run() {
String filteredText = text.toString();
//Text must contain @
if (filteredText.contains("@")) {
filteredText = Utils.getAtRefText(filteredText, getSelectionEnd());
superFiltering(filteredText, keyCode);
}
}
});
}
private void superFiltering(final CharSequence text, final int keyCode) {
super.performFiltering(text, keyCode);
}