AutoCompleteTextView单击侦听器无法正常工作

时间:2018-05-14 14:34:28

标签: android textview click autocompletetextview

我的autoCompleteTextView的点击监听器不起作用,但我不知道为什么。

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.userstatuslayout, R.id.listusername, values);

    editText.setThreshold(1);
    editText.setDropDownAnchor(R.id.districtsearch);
    editText.setAdapter(adapter);


    editText.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            String selection=(String)parent.getItemAtPosition(position);
            Toasty.info(getApplicationContext(),selection).show();

1 个答案:

答案 0 :(得分:0)

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        R.layout.userstatuslayout, R.id.listusername, values);
             AutoCompleteTextView textView = (AutoCompleteTextView)
                     findViewById(R.id...);
             textView.setAdapter(adapter);
         }
     }

你的ItemClickListener应该是:

   @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Toast.makeText(AutoCompleteActivity.this,
        "Clicked item from auto completion list "
                            + adapterView.getItemAtPosition(i)
                    , Toast.LENGTH_SHORT).show();