FileDocCategorySizeDatePackage
ScrollViewButtonsAndLabels.javaAPI DocAndroid 1.5 API2685Wed May 06 22:42:02 BST 2009com.android.frameworktest.scroll

ScrollViewButtonsAndLabels

public class ScrollViewButtonsAndLabels extends android.app.Activity
Basic scroll view example

Fields Summary
private android.widget.ScrollView
mScrollView
private android.widget.LinearLayout
mLinearLayout
private int
mNumGroups
Constructors Summary
Methods Summary
public android.widget.ButtongetButton(int groupNum)

        if (groupNum > mNumGroups) {
            throw new IllegalArgumentException("groupNum > " + mNumGroups);
        }
        return (Button) mLinearLayout.getChildAt(2*groupNum);
    
public android.widget.LinearLayoutgetLinearLayout()

        return mLinearLayout;
    
public intgetNumButtons()

        return mNumGroups;
    
public android.widget.ScrollViewgetScrollView()



       
        return mScrollView;
    
protected voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        setContentView(R.layout.scrollview_linear_layout);


        // estimated ratio to get enough buttons so a couple are off screen
        int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
        mNumGroups = screenHeight / 30;

        mScrollView = (ScrollView) findViewById(R.id.scrollView);
        mLinearLayout = (LinearLayout) findViewById(R.id.layout);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );

        for (int i = 0; i < mNumGroups; i++) {
            // want button to be first and last
            if (i > 0) {
                TextView textView = new TextView(this);
                textView.setText("Text View " + i);
                mLinearLayout.addView(textView, p);
            }

            Button button = new Button(this);
            button.setText("Button " + (i + 1));
            mLinearLayout.addView(button, p);
        }