Mitch D
Mitch D

Reputation: 111

AutoCompleteTextView drop down height limited in dialog popup

The dialog pop-up is located here.

How the AutoComplete results stop at the end of the pop-up view is here.

I want the results to drop down past the dialog's view to the parent view. If I can't do that then I want to limit the number of results the AutoComplete gives me to two.

This is in my on click listener for the popup menu.

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);

Upvotes: 11

Views: 10199

Answers (2)

i.n.e.f
i.n.e.f

Reputation: 1803

You should use this method to limit the height of dropdown for AutoCompleteTextView widget in xml:

android:dropDownHeight="size"

Or use this to do programmatically

autoCompleteTextView.setDropDownHeight(int);

Hope this help.

Upvotes: 19

s.d
s.d

Reputation: 29436

For the limiting number of items part: you can override getCount() of ArrayAdapter:

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

This works for filtering also.

Upvotes: 4

Related Questions