开发者

How to limit the number of dropdown items visible at a time on screen in AutoCompleteTextView?

开发者 https://www.devze.com 2022-12-28 04:57 出处:网络
I have an AutoCompleteTextView and want to limit the number of开发者_运维知识库 dropdown items visible at a time on the screen. Currently it fills up the screen but can I limit it to say 2 items with

I have an AutoCompleteTextView and want to limit the number of开发者_运维知识库 dropdown items visible at a time on the screen. Currently it fills up the screen but can I limit it to say 2 items with a scroll bar for displaying more.


Call setDropDownHeight(int height) method of AutoCompleteTextView.


public class MainActivity extends AppCompatActivity {

    AutoCompleteTextView autoCompleteTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.auto);

        String item[] = {"January", "February", "March", "April",
                "May", "June", "July", "August",
                "September", "October", "November", "December"};


        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
                android.R.layout.simple_list_item_1, item);
        autoCompleteTextView.setAdapter(adapter);
        autoCompleteTextView.setThreshold(1);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消