How to limit the number of dropdown items visible at a time on screen in AutoCompleteTextView?
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);
}
}
精彩评论