Example usage for android.widget ListView addHeaderView

List of usage examples for android.widget ListView addHeaderView

Introduction

In this page you can find the example usage for android.widget ListView addHeaderView.

Prototype

public void addHeaderView(View v, Object data, boolean isSelectable) 

Source Link

Document

Add a fixed view to appear at the top of the list.

Usage

From source file:eu.trentorise.smartcampus.eb.fragments.experience.EditExpFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    returnView = inflater.inflate(R.layout.exp_form, container, false);
    ListView list = (ListView) returnView.findViewById(R.id.exp_contents);
    registerForContextMenu(list);//  w ww  .j ava2 s.  co  m
    if (list.getFooterViewsCount() == 0) {
        View footer = getSherlockActivity().getLayoutInflater().inflate(R.layout.exp_form_footer, null);
        list.addFooterView(footer, null, false);
    }
    if (list.getHeaderViewsCount() == 0) {
        View header = getSherlockActivity().getLayoutInflater().inflate(R.layout.exp_form_header, null);
        list.addHeaderView(header, null, false);
        mTitleSwitch = new TextEditSwitch(returnView, R.id.title_switcher, R.id.title_tv, R.id.title, this);
        mTitleSwitch.setValue(exp.getTitle());
        mDescrSwitch = new TextEditSwitch(returnView, R.id.descr_switcher, R.id.description_tv,
                R.id.description, this);
        mDescrSwitch.setValue(exp.getDescription());
    }
    adapter = new ExpContentAdapter(getSherlockActivity(), R.layout.exp_contents_row, exp.getContents());
    list.setAdapter(adapter);
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position <= exp.getContents().size() && position > 0) {
                ContentRenderer.renderExternal(getActivity(), exp.getContents().get(position - 1));
            }
        }

    });

    updateCollectionTV();
    if (exp.getId() == null) {
        new LoadAddressTask().execute();
    } else {
        updateFooterTV(exp.getAddress(), exp.getCreationTime());
    }
    if (exp.getTags() != null) {
        ((TextView) returnView.findViewById(R.id.tags_tv)).setText(Concept.toSimpleString(exp.getTags()));
    }

    ((TextView) returnView.findViewById(R.id.tags_tv)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            TaggingDialogFragment taggingDialog = new TaggingDialogFragment();
            taggingDialog.setArguments(TaggingDialogFragment.prepare(Concept.convertToSS(exp.getTags())));
            taggingDialog.show(getActivity().getSupportFragmentManager(), "tags");
        }
    });

    returnView.findViewById(R.id.place_box).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogFragment textFragment = new EditPositionFragment();
            textFragment.setArguments(
                    EditPositionFragment.prepare(exp.getAddress() == null ? "" : exp.getAddress()));
            textFragment.show(getActivity().getSupportFragmentManager(), "exp_position");
        }
    });

    return returnView;
}

From source file:com.qianjiang.framework.widget.pulltorefresh.PullToRefreshListView.java

@Override
protected final ListView createRefreshableView(Context context, AttributeSet attrs) {
    ListView lv = new InternalListView(context, attrs);
    // Get Styles from attrs
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh);

    // Create Loading Views ready for use later
    FrameLayout frame = new FrameLayout(context);
    mHeaderLoadingView = new HeaderLoadingLayout(context, Mode.PULL_DOWN_TO_REFRESH, a);
    frame.addView(mHeaderLoadingView, android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    mHeaderLoadingView.setVisibility(View.GONE);
    lv.addHeaderView(frame, null, false);

    mLvFooterLoadingFrame = new FrameLayout(context);
    mFooterLoadingView = new FooterLoadingLayout(context, Mode.PULL_UP_TO_REFRESH, a);
    mLvFooterLoadingFrame.addView(mFooterLoadingView, android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    mFooterLoadingView.setVisibility(View.GONE);

    a.recycle();/*from w  ww .  j  a  va  2 s .co m*/

    // Set it to this so it can be used in ListActivity/ListFragment
    lv.setId(android.R.id.list);
    return lv;
}

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

/**
 * Prepares and shows the specified menu immediately.
 *
 * @param menu the menu to show/*from w w w  . j a v  a  2s  .  c o  m*/
 */
private void showMenu(@NonNull MenuBuilder menu) {
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly);

    // Apply "force show icon" setting. There are 3 cases:
    // (1) This is the top level menu and icon spacing is forced. Add spacing.
    // (2) This is a submenu. Add spacing if any of the visible menu items has an icon.
    // (3) This is the top level menu and icon spacing isn't forced. Do not add spacing.
    if (!isShowing() && mForceShowIcon) {
        // Case 1
        adapter.setForceShowIcon(true);
    } else if (isShowing()) {
        // Case 2
        adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu));
    }
    // Case 3: Else, don't allow spacing for icons (default behavior; do nothing).

    final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth);
    final MenuPopupWindow popupWindow = createPopupWindow();
    popupWindow.setAdapter(adapter);
    popupWindow.setWidth(menuWidth);
    popupWindow.setDropDownGravity(mDropDownGravity);

    final CascadingMenuInfo parentInfo;
    final View parentView;
    if (mShowingMenus.size() > 0) {
        parentInfo = mShowingMenus.get(mShowingMenus.size() - 1);
        parentView = findParentViewForSubmenu(parentInfo, menu);
    } else {
        parentInfo = null;
        parentView = null;
    }

    if (parentView != null) {
        // This menu is a cascading submenu anchored to a parent view.
        popupWindow.setTouchModal(false);
        popupWindow.setEnterTransition(null);

        final @HorizPosition int nextMenuPosition = getNextMenuPosition(menuWidth);
        final boolean showOnRight = nextMenuPosition == HORIZ_POSITION_RIGHT;
        mLastPosition = nextMenuPosition;

        final int[] tempLocation = new int[2];

        // This popup menu will be positioned relative to the top-left edge
        // of the view representing its parent menu.
        parentView.getLocationInWindow(tempLocation);
        final int parentOffsetLeft = parentInfo.window.getHorizontalOffset() + tempLocation[0];
        final int parentOffsetTop = parentInfo.window.getVerticalOffset() + tempLocation[1];

        // By now, mDropDownGravity is the resolved absolute gravity, so
        // this should work in both LTR and RTL.
        final int x;
        if ((mDropDownGravity & Gravity.RIGHT) == Gravity.RIGHT) {
            if (showOnRight) {
                x = parentOffsetLeft + menuWidth;
            } else {
                x = parentOffsetLeft - parentView.getWidth();
            }
        } else {
            if (showOnRight) {
                x = parentOffsetLeft + parentView.getWidth();
            } else {
                x = parentOffsetLeft - menuWidth;
            }
        }

        popupWindow.setHorizontalOffset(x);

        final int y = parentOffsetTop;
        popupWindow.setVerticalOffset(y);
    } else {
        if (mHasXOffset) {
            popupWindow.setHorizontalOffset(mXOffset);
        }
        if (mHasYOffset) {
            popupWindow.setVerticalOffset(mYOffset);
        }
        final Rect epicenterBounds = getEpicenterBounds();
        popupWindow.setEpicenterBounds(epicenterBounds);
    }

    final CascadingMenuInfo menuInfo = new CascadingMenuInfo(popupWindow, menu, mLastPosition);
    mShowingMenus.add(menuInfo);

    popupWindow.show();

    // If this is the root menu, show the title if requested.
    if (parentInfo == null && mShowTitle && menu.getHeaderTitle() != null) {
        final ListView listView = popupWindow.getListView();
        final FrameLayout titleItemView = (FrameLayout) inflater
                .inflate(R.layout.abc_popup_menu_header_item_layout, listView, false);
        final TextView titleView = (TextView) titleItemView.findViewById(android.R.id.title);
        titleItemView.setEnabled(false);
        titleView.setText(menu.getHeaderTitle());
        listView.addHeaderView(titleItemView, null, false);

        // Show again to update the title.
        popupWindow.show();
    }
}

From source file:com.csipsimple.ui.messages.ConversationsListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View v = inflater.inflate(R.layout.message_list_fragment, container, false);

    ListView lv = (ListView) v.findViewById(android.R.id.list);

    View.OnClickListener addClickButtonListener = new View.OnClickListener() {
        @Override//from  w  w  w. j  a  v  a  2 s  .c o  m
        public void onClick(View v) {
            onClickAddMessage();
        }
    };

    // Header view
    mHeaderView = (ViewGroup) inflater.inflate(R.layout.conversation_list_item, lv, false);
    ((TextView) mHeaderView.findViewById(R.id.from)).setText(R.string.new_message);
    ((TextView) mHeaderView.findViewById(R.id.subject)).setText(R.string.create_new_message);
    mHeaderView.findViewById(R.id.quick_contact_photo).setVisibility(View.GONE);
    mHeaderView.setOnClickListener(addClickButtonListener);
    // Empty view
    Button bt = (Button) v.findViewById(android.R.id.empty);
    bt.setOnClickListener(addClickButtonListener);

    lv.addHeaderView(mHeaderView, null, true);
    lv.setOnCreateContextMenuListener(this);

    return v;
}

From source file:com.csipsimple.ui.account.AccountsEditListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ListView lv = getListView();

    //getListView().setSelector(R.drawable.transparent);
    lv.setCacheColorHint(Color.TRANSPARENT);

    // View management
    View detailsFrame = getActivity().findViewById(R.id.details);
    dualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;

    if (savedInstanceState != null) {
        // Restore last state for checked position.
        curCheckPosition = savedInstanceState.getLong(CURRENT_CHOICE, SipProfile.INVALID_ID);
        //curCheckWizard = savedInstanceState.getString(CURRENT_WIZARD);
    }//  w ww.j a v a  2 s  . com
    setListShown(false);
    if (mAdapter == null) {
        if (mHeaderView != null) {
            lv.addHeaderView(mHeaderView, null, true);
        }
        mAdapter = new AccountsEditListAdapter(getActivity(), null);
        mAdapter.setOnCheckedRowListener(this);
        //getListView().setEmptyView(getActivity().findViewById(R.id.progress_container));
        //getActivity().findViewById(android.R.id.empty).setVisibility(View.GONE);
        setListAdapter(mAdapter);
        registerForContextMenu(lv);

        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getLoaderManager().initLoader(0, null, this);

        lv.setVerticalFadingEdgeEnabled(true);
    }

    if (dualPane) {
        // In dual-pane mode, the list view highlights the selected item.
        Log.d("lp", "dual pane mode");
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        //lv.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
        lv.setVerticalScrollBarEnabled(false);
        lv.setFadingEdgeLength(50);

        updateCheckedItem();
        // Make sure our UI is in the correct state.
        //showDetails(curCheckPosition, curCheckWizard);
    } else {
        //getListView().setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT);
        lv.setVerticalScrollBarEnabled(true);
        lv.setFadingEdgeLength(100);
    }
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

private int addSilendStaticItem(ListView listView, int textResId) {

    silentView = getLayoutInflater().inflate(R.layout.tab_picker_item, listView, false);
    TextView textView = (TextView) silentView.findViewById(R.id.title);
    textView.setText(textResId);/*w  w w  . j  ava2s.c  o m*/
    listView.addHeaderView(silentView, null, true);
    mStaticItemCount++;
    return listView.getHeaderViewsCount() - 1;
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

private int addDefaultStaticItem(ListView listView, int textResId) {

    defaultView = getLayoutInflater().inflate(R.layout.tab_picker_item, listView, false);
    TextView textView = (TextView) defaultView.findViewById(R.id.title);
    textView.setText(textResId);/*from w ww  . j a  v  a2 s. com*/
    listView.addHeaderView(defaultView, null, true);
    mStaticItemCount++;
    return listView.getHeaderViewsCount() - 1;
}

From source file:de.vanita5.twittnuker.fragment.support.StatusFragment.java

@Override
protected void setListHeaderFooters(final ListView list) {
    if (getActivity() == null || isDetached())
        return;//from   ww  w.  j a  v  a  2  s  . c o  m
    list.addHeaderView(mHeaderView, null, true);
}

From source file:org.kontalk.ui.AbstractComposeFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // setListAdapter() is post-poned

    ListView list = getListView();

    setMultiChoiceModeListener(this);

    // add header view (this must be done before setting the adapter)
    mHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.message_list_header, list, false);
    mNextPageButton = mHeaderView.findViewById(R.id.load_next_page);
    mNextPageButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww  w .  ja  v a  2  s  .  c om*/
        public void onClick(View v) {
            // disable button in the meantime
            enableHeaderView(false);
            // start query for the next page
            startMessagesQuery(mQueryHandler.getLastId());
        }
    });
    list.addHeaderView(mHeaderView, null, false);

    // set custom background (if any)
    ImageView background = (ImageView) getView().findViewById(R.id.background);
    Drawable bg = Preferences.getConversationBackground(getActivity());
    if (bg != null) {
        background.setScaleType(ImageView.ScaleType.CENTER_CROP);
        background.setImageDrawable(bg);
    } else {
        background.setScaleType(ImageView.ScaleType.FIT_XY);
        background.setImageResource(R.drawable.app_background_tile);
    }

    processArguments(savedInstanceState);
    initAttachmentView();
}