【问题标题】:AutoCompleteTextView drop down height limited in dialog popup对话框弹出中的 AutoCompleteTextView 下拉高度限制
【发布时间】:2012-11-12 04:47:59
【问题描述】:

弹出对话框位于here

自动完成结果在弹出视图末尾停止的方式是here

我希望结果从对话框视图下拉到父视图。如果我不能这样做,那么我想将 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);

【问题讨论】:

    标签: android autocompletetextview


    【解决方案1】:

    您应该使用此方法来限制 xml 中 AutoCompleteTextView 小部件的下拉高度:

    android:dropDownHeight="size"
    

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

    autoCompleteTextView.setDropDownHeight(int);
    

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

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

      @Override
      public int getCount() {
         return Math.min(2,super.getCount());
      }
      

      这也适用于过滤。

      【讨论】:

      • 我应该更清楚。我不希望将显示的总结果限制为 2。我希望通过滚动其余结果将一次显示的最大结果数量限制为两个。
      • 是的,这不是他要问的。这只是限制了结果数。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 2023-02-01
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多