5

キーを押すたびに PopupWindow を更新する EditText があります。.setFocusable(true) を使用して PopupWIndow を作成すると、フォーカスが取得され、入力を続けることができなくなります。ただし、.setFocusable(false) を使用すると、PopupWindow 内の ListView は OnItemClickedListener をトリガーしません。

フォーカスを取得せずに PopupWindow を作成することは可能ですが、その中のウィジェットをクリック可能にすることはできますか?

(PopupWidow はオートコンプリート用ではないため、AutoCompleteTextView は必要ないと思います)

4

1 に答える 1

3

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();
        }
    }
});
于 2012-12-10T17:11:59.060 に答える