0

我在ExpandableListView, 的每一個子項目一個EditText,但有一個問題: 當我點擊的EditText,有時光標正常閃爍, 但有時光標不會出現, 或光標顯示但不閃爍。光標的EditText在ExpandableListView的不閃爍或出現

我試過很多方法,但沒有人工作。

下面是我試過的方法,但不工作:

  1. 一套用於兒童的每一項的EditText在Java中

    View.OnFocusChangeListener onFocus = new View.OnFocusChangeListener() { 
        @Override 
        public void onFocusChange(View v, boolean hasFocus) { 
         v.dispatchWindowFocusChanged(hasFocus); 
        } 
    }; 
    
  2. 一套用於ExpandableListView

    android:descendantFocusability="afterDescendants" 
    android:focusable="false" 
    
  3. 設置爲xml中的子項目

    android:textCursorDrawable="@null" 
        android:cursorVisible="true" 
    

我不知道這個問題的想法,請大家幫忙,非常感謝~~~

+0

是否在子項中添加了android:focusableInTouchMode =「true」和android:focusable =「false」? – Nas

+0

@Nas謝謝〜我只是試過你的代碼,它不起作用。 TAT – DawnYu

+0

您是否找到任何解決方案? – Ircover

回答

0

當我發現當某種原因EditText的內心無效計時器停止它的發生。我不知道爲什麼。

我所能做的就是創建我自己的Handler,以使我的課內視圖無效,延伸到EditText

@Override 
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 
    super.onFocusChanged(focused, direction, previouslyFocusedRect); 
    if(focused) { 
     handler.postDelayed(this, 200); 
    } else { 
     handler.removeCallbacks(this); 
    } 
} 

@Override 
public void run() { 
    invalidate(); 
    new Thread(new Runnable() { 
     @Override 
     public void run() { 
      try { 
       Thread.sleep(250); 
       if(hasFocus()) { 
        handler.post(MyEditText.this); 
       } 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 
    }).start(); 
} 

我不認爲這是一個好的解決方案。如果你知道的更好,請寫下來。