Android: AutoCompleteTextView show suggestions when no text entered

后端 未结 14 1938
-上瘾入骨i
-上瘾入骨i 2020-11-27 11:20

I am using AutoCompleteTextView, when the user clicks on it, I want to show suggestions even if it has no text - but setThreshold(0) works exactly

14条回答
  •  我在风中等你
    2020-11-27 12:25

    Just paste this to your onCreate Method in Java

    final ArrayAdapter arrayAdapter = new ArrayAdapter<>(
                this, android.R.layout.simple_spinner_dropdown_item,
                getResources().getStringArray(R.array.Loc_names));
    
        textView1 =(AutoCompleteTextView) findViewById(R.id.acT1);
        textView1.setAdapter(arrayAdapter);
    
        textView1.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(final View arg0) {
                textView1.setMaxLines(5);
                textView1.showDropDown();
    
            }
        });
    

    And this to your Xml file...

    
    

    And create an Array in string.xml under Values...

    
    
            Pakistan
            Germany
            Russia/NCR
            China
            India
            Sweden
            Australia
        
    

    And you are good to go.

提交回复
热议问题