2012-04-16 56 views

回答

0

下面是ArrayAdapter的一個子類,它將結果限制在您選擇的範圍內。

public class LimitArrayAdapter<T> extends ArrayAdapter<T> { 

    final int LIMIT = 5; 
    //overload other constructors you're using 
    public LimitArrayAdapter(Context context, int textViewResourceId, 
          List<T> objects) { 
     super(context, textViewResourceId, objects); 
    } 

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

} 

Ofcourse,這是您將如何使用它

autoCompleteTextView.setAdapter(new LimitArrayAdapter<String>(this, 
                   android.R.layout.simple_dropdown_item_1line, 
                   list));