2013-07-17 2 views
2

편집을 마친 후에 안드로이드 대화 상자에 EditText (searcField)가 있습니다. 대화 상자를 닫습니다.안드로이드 대화 상자의 clearFocus가 작동하지 않습니다.

다른 EditText로 이동하면 포커스는 여전히 searchField에 있습니다.

아이디어가 있으십니까?

감사

편집 : 여기에 게시 할 너무 많이가,이 조금 내 문제를 이해하는 데 도움이 될 수 있기를 바랍니다.

고객 대화보기

  <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:paddingTop="5dip" 
       android:orientation="horizontal" > 

       <EditText 
        android:id="@+id/search_field" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:gravity="left" 
        android:inputType="textNoSuggestions|textVisiblePassword" 
        android:layout_weight="0.70" 
        android:hint="type item name to search"/> 


      </LinearLayout> 


      <ListView  
      android:id="@+id/itemList"  
      android:layout_width="fill_parent"  
      android:layout_height="wrap_content" 
      android:divider="#00000000" 
      android:descendantFocusability="beforeDescendants"  
      android:scrollbars="none"/> 

     </LinearLayout> 

자바 코드

View searchView = getActivity().getLayoutInflater().inflate(R.layout.search, null, false); 
    EditText searchField = (EditText)productEditView.findViewById(R.id.search_field); 
    searchField.addTextChangedListener(this); 
    ... 

    public void afterTextChanged(Editable text) { 
     if (searchField.hasFocus()) { 
      Log.i("MyApp", "searchField is still focused"); 
      return; 
     } 
     if (otherField.hasFocus()){ 
      Log.i("MyApp", "other field"); 
      return; 
     } 
    } 
+0

당신은 초점이 표시되어 있지 않은 대화 상자의 필드에 말을? 초점이 맞다는 것을 어떻게 아십니까? – invertigo

+0

네, 맞습니다. 초점은 여전히 ​​대화 상자에 있습니다. addTextChangedListener를 사용하여 모든 textFields를 등록했습니다. 그런 다음 afterTextChanged 콜백에서 (searchField.hasFocus())를 확인합니다. 항상 true입니다. – triston

+0

어쩌면 코드를 게시하여 – invertigo

답변

2

또 다른, 내가 정기적으로 부모 뷰 (있는 LinearLayout, RelativeLayout의 등)에 android:focusable="true"android:focusableInTouchMode="true" 설정되어 사용이 다소 해키 솔루션이기는하지만 EditText의 clearFocus()를 할 수 있거나, 첫 번째 EditText가 자동으로 집중되지 않도록 Activity/Fragment를 열려면 레이아웃 레이아웃을 수정해야합니다.

는 XML을 통해 달성 될 수 있지만 대화 상자가 같은 일을 기각 할 때 프로그래밍을 할 수 있을지 모르겠어요
2

: 당신의 대화는 단순히 onDismiss을 무시 해제 할 때

mView.setFocusableInTouchMode(true); 
mView.requestFocus(); 

알고() 콜백 메소드.

0

당신은 당신의 편집 코드 이벤트 뒤에 다음 코드를 추가해야합니다 :

seachview.clearfocus(); 
edittext.requestfocus(); 
관련 문제