Show all items in AutocompleteTextView without writing text

前端 未结 12 837
萌比男神i
萌比男神i 2020-12-29 01:05

I have a AutocompleteTextView and it works fine. When I write a word it shows the relevant result but I want to show all items without writing any word in AutocompleteTextVi

12条回答
  •  余生分开走
    2020-12-29 01:36

    Here an approach with onclicklistener as I found tat onTouch was a bit irritating when trying to scroll. mOccupation is the AutocompleteTextView in question.

        mOccupation=(AutoCompleteTextView) findViewById(R.id.actv_occupation);
        ArrayAdapter occupationAdapter=new ArrayAdapter 
        (NewClientActivity.this,
                android.R.layout.simple_list_item_1,
                getResources().getStringArray(R.array.occupation_array));
        mOccupation.setAdapter(occupationAdapter);
        mOccupation.setKeyListener(null);
        mOccupation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //mOccupation.setText(null);
                ((AutoCompleteTextView) view).showDropDown();
                return;
            }
        });
    

    I managed to put it all into a Textinputlayout with the following xml specifications:

    
    
        
    
    

提交回复
热议问题