List13public class List13 extends android.app.ListActivity implements ListView.OnScrollListenerDemonstrates how a list can avoid expensive operations during scrolls or flings. In this
case, we pretend that binding a view to its data is slow (even though it really isn't). When
a scroll/fling is happening, the adapter binds the view to temporary data. After the scroll/fling
has finished, the temporary data is replace with the actual data. |
Fields Summary |
---|
private android.widget.TextView | mStatus | private boolean | mBusy | private String[] | mStrings |
Methods Summary |
---|
public void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.list_13);
mStatus = (TextView) findViewById(R.id.status);
mStatus.setText("Idle");
// Use an existing ListAdapter that will map an array
// of strings to TextViews
setListAdapter(new SlowAdapter(this));
getListView().setOnScrollListener(this);
| public void | onScroll(android.widget.AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
| public void | onScrollStateChanged(android.widget.AbsListView view, int scrollState)
switch (scrollState) {
case OnScrollListener.SCROLL_STATE_IDLE:
mBusy = false;
int first = view.getFirstVisiblePosition();
int count = view.getChildCount();
for (int i=0; i<count; i++) {
TextView t = (TextView)view.getChildAt(i);
if (t.getTag() != null) {
t.setText(mStrings[first + i]);
t.setTag(null);
}
}
mStatus.setText("Idle");
break;
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
mBusy = true;
mStatus.setText("Touch scroll");
break;
case OnScrollListener.SCROLL_STATE_FLING:
mBusy = true;
mStatus.setText("Fling");
break;
}
|
|