コード例 #1
0
  private void onDataChanged() {
    adapterDataCount = adapter.getCount();
    int activeIndex;
    if (adapterIndex < 0) {
      activeIndex = 0;
    } else {
      activeIndex = Math.min(adapterIndex, adapterDataCount - 1);
    }

    releaseViews();
    setSelection(activeIndex);
  }
コード例 #2
0
  public void setAdapter(Adapter adapter, int initialPosition) {
    if (this.adapter != null) {
      this.adapter.unregisterDataSetObserver(adapterDataObserver);
    }

    Assert.assertNotNull("adapter should not be null", adapter);

    this.adapter = adapter;
    adapterDataCount = adapter.getCount();

    adapterDataObserver = new MyDataSetObserver();
    this.adapter.registerDataSetObserver(adapterDataObserver);
    if (adapterDataCount > 0) {
      setSelection(initialPosition);
    }
  }