0

わかりました、これが私の状況です。OnKeyのリスナーが必要なAutoCompleteTextViewがありますが、これは問題ありませんが、「キー付き」のビューが実際のテキストフィールドであり、オートコンプリートの選択の1つではない場合にのみ、onKeyを消費したいと考えています。選択がヒットした場合は、onItemClickedListener で処理します。したがって、私のコードは次のようになります。

public class MyFragment extends Fragment implement OnKeyListener {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i(LOG_TAG, "Fragment Inflated");
    View view = inflater.inflate(R.layout.my_layout, container, false);
    final  AutoCompleteTextView autoComplete = (AutoCompleteTextView)v.findViewById(R.id.my_autocomplete_id);
    autoComplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
           //just setting the text from the selection
            String s =  adapterView.getItemAtPosition(i).toString();
            autoComplete.setText(s);

        }
    });
    return view;
}


@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if(v instanceof AutoCompleteTextView)
    {
        AutoCompleteTextView av = (AutoCompleteTextView)v;
        //I need to be able to tell if this is the text field or a selection
        // from the autocomplete!!
    }

}

OnKey は itemclicked の前に起動しますが、これは予想どおりです (これを変更できるとは思いません)。そのため、上で述べたように、編集テキスト領域が「キー」されているかどうかを確実に検出する必要があります。選択。

デバッガーで AutoCompleteTextView オブジェクトを Google で検索して調べましたが、必要なものを示すものは何も表示されません。

これを処理する方法について何か提案はありますか? 私が言ったように、クリックされているテキスト領域の onKey を処理できる必要があります。OnKey の前にどうにかして selectedItem のクリックを処理できれば、フラグを設定できますが、やはりそれは不可能だと思います。アドバイスをいただければ幸いです。どうもありがとう!

4

1 に答える 1

0

だから私は自分の質問に答えるのが好きではありませんが、答えを見つけました.そもそもどうしてそれを見逃したのかわかりません.テキストフィールドにいる場合、AutoCompleTextView.getListSelection()は-1を返します.

于 2013-10-17T20:42:39.660 に答える