Code example for LinearLayout

Methods: addViewsetGravity, setId, setLayoutParams, setVisibility

0
    } 
 
    private void setupIdleList() { 
        Context context = getContext();
 
        mFooterView = new LinearLayout(context);
        mFooterView.setId(INTERNAL_FOOTER_ID);
        mFooterView.setGravity(Gravity.CENTER);
        mFooterView.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
 
        mProgress = new ProgressBar(context, null, android.R.attr.progressBarStyle);
        mProgress.setId(INTERNAL_PROGRESS_ID);
        mProgress.setIndeterminate(true);
        mProgress.setVisibility(View.GONE);
        final LayoutParams progressLayoutParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
        mProgress.setLayoutParams(progressLayoutParams);
 
        mFooterView.addView(mProgress);
 
        mStandardEmptyView = new TextView(context);
        mStandardEmptyView.setId(INTERNAL_EMPTY_ID);
        mStandardEmptyView.setGravity(Gravity.CENTER);
        mStandardEmptyView.setVisibility(View.GONE);
        mStandardEmptyView.setPadding(10, 15, 10, 15);
        mStandardEmptyView.setText("That's all, folks!");
 
        mFooterView.addView(mStandardEmptyView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
 
        setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
 
        setFooterDividersEnabled(true);
        addFooterView(mFooterView, null, false);
 
        setItemsCanFocus(true);
        setDrawSelectorOnTop(true);
 
		/* A tiny hack to get the ProgressBar to show */ 
        mListShown = true;
        setListShown(true); 
        setFooterShown(true); 
    } 
 
    public BaseListAdapter<T> getListAdapter() { 
        final ListAdapter adapter = getAdapter();
 
        if (adapter instanceof HeaderViewListAdapter) {
            return (BaseListAdapter<T>) ((HeaderViewListAdapter) adapter).getWrappedAdapter();
        } else { 
            return (BaseListAdapter<T>) getAdapter();
        } 
    } 
 
    @Override 
    public void setAdapter(ListAdapter adapter) {
        if (!(adapter instanceof BaseListAdapter)) {
            throw new IllegalArgumentException("IdleList must use a BaseListAdapter.");
        } 
 
        boolean hadAdapter = getListAdapter() != null;
 
        super.setAdapter(adapter);
 
        if (!(mListShown || hadAdapter)) {
            setListShown(true, getWindowToken() != null);
        } 
    } 
 
    public CharSequence getTitle() {
        return mTitle;
    } 
 
    public void setTitle(CharSequence title) {
        mTitle = title;
    } 
 
    public void setEmptyText(CharSequence text) {
        if (mStandardEmptyView == null) {
            throw new IllegalStateException("Can't be used with a custom content view");
        } 
        mStandardEmptyView.setText(text);
        if (mEmptyText == null) {
            setEmptyView(mStandardEmptyView);
        } 
        mEmptyText = text;
    } 
 
    public void setListShown(boolean shown) {
        setListShown(shown, true);
    } 
 
    public void setListShownNoAnimation(boolean shown) {
        setListShown(shown, false);
    } 
 
    private void setListShown(boolean shown, boolean animate) {
        if (mListShown == shown) {
            return; 
        } 
        mListShown = shown;
        final Context context = getContext();
        if (shown) {
            if (animate) {
                startAnimation(AnimationUtils.loadAnimation(context, android.R.anim.fade_in));
            } else { 
                clearAnimation();
            } 
            setVisibility(View.VISIBLE);
        } else { 
            if (animate) {
                startAnimation(AnimationUtils.loadAnimation(context, android.R.anim.fade_out));
            } else { 
                clearAnimation();
            } 
            setVisibility(View.GONE);
        } 
    } 
 
    public void setFooterShown(boolean shown) {
        if (shown) {
            mFooterView.setVisibility(View.VISIBLE);
        } else { 
            mFooterView.setVisibility(View.GONE);
        } 
    } 
 
    public ProgressBar getProgressBar() {
        return mProgress;