2016-04-25 115 views
0

我遇到了問題EditTextAndroid EditText setText導致軟鍵盤凍結

我實現了一個TextWatcher我檢查afterTextChanged每次突出一個AsyncTask一些特定的關鍵字,並設置在onPostExcute文本(我只在這裏觸摸UI),但是當setText被稱爲onPostExcute軟鍵盤凍結(該應用程序沒有凍結)。

public class AsyncHighLight extends AsyncTask<String,String,String> 
{ 
    @Override 
    protected String doInBackground(String[] p1){ 
     return SyntaxHighlighter.getInstance(MainActivity.this).highlight(p1[0]); 
    } 

    @Override 
    protected void onPostExecute(String result){ 
     et.setText(Html.fromHtml(result)); 
    } 
} 

這裏的高亮度代碼

public String highlight(String s){ 
    String newString = s; 
    newString = newString.replace("\n","<br>"); 
    for (int i = 0 ; i < currentLang.keyword.length ; i ++){ 
     newString = newString.replace(currentLang.keyword[i],warpColorTag(currentLang.keyword[i])); 
    } 
    return newString; 
} 
+0

就直接返回結果和應用內的活動範圍僅 – Haroon

+0

@Haroon您的意思是不是設置它onPostExecute et.settext()?我會嘗試 – BennyKok

+0

@哈龍如果我不使用異步任務,ui凍結 – BennyKok

回答

2

你必須寫終止afterTextChange(邏輯)TextWatcher的方法,每當文本得到了改變afterTextChange()將被調用,每afterTextChange時間( )被調用時,突出顯示AsyncTask中的一些特定關鍵字,並再次在onPostExecute()中調用,並且它將再次設置爲Text()。所以你必須找到終止afterTextChange()邏輯的方式。爲了更好的幫助,請發佈TextWatcher代碼。

1

這是由於這樣的原因,只要你在onpostexecute中設置文本,textchange事件再次觸發,並再次進入異步任務,因此它進入一個無限循環。 您應該使用一個布爾追查事件是否從onpostexecute或鍵盤輸入genrated