HorizontalListView 原创的setSelection()是没有实现的,后来有国人重写了HorizontalListView。
在这个类里加入了
@Override
public void setSelection(int position) {
setSelectionFromLeft(position, 0);
}
/**
* Sets the selected item and positions the selection y pixels from the left edge
* of the ListView. (If in touch mode, the item will not be selected but it will
* still be positioned appropriately.)
*
* @param position Index (starting at 0) of the data item to be selected.
* @param x The distance from the left edge of the ListView (plus padding) that the
* item will be positioned.
*/
public void setSelectionFromLeft(int position, int x) {
if (setSelectionFrom(position, x) >= 0) {
requestLayout();
}
}