2012-04-27 78 views
4

我有一個EditText,它在每個按鍵上更新一個PopupWindow。如果我用.setFocusable(true)創建PopupWIndow,那麼它抓住焦點,我不能繼續打字。但是,如果我使用.setFocusable(false),PopupWindow內的ListView不會觸發OnItemClickedListener。避免PopupWindow抓焦點

它是否有可能創建一個PopupWindow沒有抓住焦點,但仍然使它內部的小部件可點擊?

(該PopupWidow不是自動完成的,所以我不認爲AutoCompleteTextView是什麼,我需要)

回答

2

我想你可以使用ListPopupWindow。它爲你處理一些焦點問題。這是一個非常簡單的代碼。它仍然需要添加更多聽衆來滿足您的需求。但它把重點放在了問題上。

ListPopupWindow popup; 
EditText editText; 
String[] strAry = {"a", "2", "3", "4", "5", "6", "7", "8", "9"}; 

editText=(EditText)this.findViewById(R.id.editText); 
popup= new ListPopupWindow(this.getApplicationContext()); 
popup.setAdapter(new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,strAry)); 
popup.setAnchorView(editText); 
popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED); 

editText.setOnClickListener(new OnClickListener(){ 
    @Override 
    public void onClick(View eventView) { 
     if(!popup.isShowing()){ 
      popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED); 
      popup.show(); 
     } 
    } 
}); 
editText.addTextChangedListener(new s(){ 
    @Override 
    public void afterTextChanged(Editable arg0) {} 
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, 
     int arg3) {} 
    @Override 
    public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { 
     if(!popup.isShowing()){ 
      popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED); 
      popup.postShow(); 
     } 
    } 
}); 
+0

我使用的PopupWindow我也面臨同樣的問題,如果任何解決方案與PopupWindow。請分享。 – 2013-09-25 08:31:52