AutoCompleteTextView下拉高度限制在对话框弹出窗口中

Mit*_*h D 11 android autocompletetextview

对话框弹出窗口位于此处.

自动完成结果如何停在弹出视图的到底是在这里.

我希望结果从对话框的视图下拉到父视图.如果我不能这样做,那么我想限制AutoComplete给我两个结果的数量.

这是我弹出菜单的单击监听器.

addDialog.setContentView(R.layout.shoppinglistadd);

/**Capture the AutoCompleteTextView widget*/
final AutoCompleteTextView autoCompleteTV 
  = (AutoCompleteTextView) addDialog.findViewById(R.id.productEnteredShop);
/**Fills the autocomplete with possibilities*/
String[] acArray = getResources().getStringArray(R.array.completeFoodsList);
/**Create a new ArrayAdapter and bind shoppinglistitem.xml to each list item*/
ArrayAdapter<String> autoCompleteAdapter 
  = new ArrayAdapter<String>(ShoppingList.this, R.layout.shoppinglistitem, acArray);
/**Associate the adapter with textView*/
autoCompleteTV.setAdapter(autoCompleteAdapter);
Run Code Online (Sandbox Code Playgroud)

i.n*_*e.f 12

您应该使用此方法来限制AutoCompleteTextViewxml中窗口小部件的下拉列表的高度:

android:dropDownHeight="size"
Run Code Online (Sandbox Code Playgroud)

或者使用它以编程方式执行

autoCompleteTextView.setDropDownHeight(int);
Run Code Online (Sandbox Code Playgroud)

希望这有帮助.


S.D*_*.D. 5

对于部分项目的限制数:您可以覆盖getCount()ArrayAdapter:

@Override
public int getCount() {
   return Math.min(2,super.getCount());
}
Run Code Online (Sandbox Code Playgroud)

这也适用于过滤.

  • 我应该更清楚.我不打算将总结果显示限制为2.我希望通过滚动其余部分将一次显示的最大结果数量限制为2. (2认同)