/** * Append header to the rear of the mHeaderLayout. * * @param header */ public void addHeaderView(View header) { addHeaderView(header, -1); }
/** * Add header view to mHeaderLayout and set header view position in mHeaderLayout. * When index = -1 or index >= child count in mHeaderLayout, * the effect of this method is the same as that of {@link #addHeaderView(View)}. * * @param header * @param index the position in mHeaderLayout of this header. * When index = -1 or index >= child count in mHeaderLayout, * the effect of this method is the same as that of {@link #addHeaderView(View)}. */ public void addHeaderView(View header, int index) { addHeaderView(header, index, LinearLayout.VERTICAL); }
private void addHeaderView() { View headerView = getLayoutInflater().inflate(R.layout.rv_header, null); headerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mAdapter.addHeaderView(headerView); headerView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "your click headerView", Snackbar.LENGTH_SHORT).show(); } }); }
private void addHeaderView() { View headerView = getLayoutInflater().inflate(R.layout.rv_header, null); headerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mAdapter.addHeaderView(headerView); headerView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "your click headerView", Snackbar.LENGTH_SHORT).show(); } }); }