FileDocCategorySizeDatePackage
List13.javaAPI DocAndroid 1.5 API18007Wed May 06 22:41:08 BST 2009com.example.android.apis.view

List13

public class List13 extends android.app.ListActivity implements ListView.OnScrollListener
Demonstrates 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
Constructors Summary
Methods Summary
public voidonCreate(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 voidonScroll(android.widget.AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)

    
public voidonScrollStateChanged(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;
        }