private void onDataChanged() { adapterDataCount = adapter.getCount(); int activeIndex; if (adapterIndex < 0) { activeIndex = 0; } else { activeIndex = Math.min(adapterIndex, adapterDataCount - 1); } releaseViews(); setSelection(activeIndex); }
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); } }