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

List9

public class List9 extends android.app.ListActivity implements ListView.OnScrollListener
Another variation of the list of cheeses. In this case, we use {@link AbsListView#setOnScrollListener(AbsListView.OnScrollListener) AbsListView#setOnItemScrollListener(AbsListView.OnItemScrollListener)} to display the first letter of the visible range of cheeses.

Fields Summary
private RemoveWindow
mRemoveWindow
android.os.Handler
mHandler
private android.view.WindowManager
mWindowManager
private android.widget.TextView
mDialogText
private boolean
mShowing
private boolean
mReady
private char
mPrevLetter
private String[]
mStrings
Constructors Summary
Methods Summary
public voidonCreate(android.os.Bundle savedInstanceState)

    
    
        
        super.onCreate(savedInstanceState);

        mWindowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
        
        // Use an existing ListAdapter that will map an array
        // of strings to TextViews
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mStrings));
        
        getListView().setOnScrollListener(this);
        
        LayoutInflater inflate = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        mDialogText = (TextView) inflate.inflate(R.layout.list_position, null);
        mDialogText.setVisibility(View.INVISIBLE);
        
        mHandler.post(new Runnable() {

            public void run() {
                mReady = true;
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams.TYPE_APPLICATION,
                        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                        PixelFormat.TRANSLUCENT);
                mWindowManager.addView(mDialogText, lp);
            }});
    
protected voidonDestroy()

        super.onDestroy();
        mWindowManager.removeView(mDialogText);
        mReady = false;
    
protected voidonPause()

        super.onPause();
        removeWindow();
        mReady = false;
    
protected voidonResume()

        super.onResume();
        mReady = true;
    
public voidonScroll(android.widget.AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)

        int lastItem = firstVisibleItem + visibleItemCount - 1;
        if (mReady) {
            char firstLetter = mStrings[firstVisibleItem].charAt(0);
            
            if (!mShowing && firstLetter != mPrevLetter) {

                mShowing = true;
                mDialogText.setVisibility(View.VISIBLE);
               

            }
            mDialogText.setText(((Character)firstLetter).toString());
            mHandler.removeCallbacks(mRemoveWindow);
            mHandler.postDelayed(mRemoveWindow, 3000);
            mPrevLetter = firstLetter;
        }
    
public voidonScrollStateChanged(android.widget.AbsListView view, int scrollState)

    
private voidremoveWindow()

        if (mShowing) {
            mShowing = false;
            mDialogText.setVisibility(View.INVISIBLE);
        }