Grid Layout with Header
adrian
614

Hai Adrian, 
I using recyclerview using staggered grid view, I setted header as follows. But my header hides the first item in the recycler view. please explain why first item hidden.

@Override

public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

if (holder instanceof HeaderViewHolder) {

HeaderViewHolder headerHolder = (HeaderViewHolder) holder;

// StaggeredGridLayoutManager.LayoutParams layoutParams = new

// StaggeredGridLayoutManager.LayoutParams(

// ViewGroup.LayoutParams.MATCH_PARENT,

// ViewGroup.LayoutParams.MATCH_PARENT);

StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView

.getLayoutParams();

layoutParams.setFullSpan(true);

headerHolder.itemView.setLayoutParams(layoutParams);

headerHolder.txtTitleHeader.setText(“Header”);

headerHolder.txtTitleHeader

.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

Toast.makeText(context, “Clicked Header”,

Toast.LENGTH_SHORT).show();

}

});

}

else if (holder instanceof FooterViewHolder) {

FooterViewHolder footerHolder = (FooterViewHolder) holder;

footerHolder.txtTitleFooter.setText(“Footer”);

StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

ViewGroup.LayoutParams.MATCH_PARENT);

layoutParams.setFullSpan(true);

footerHolder.itemView.setLayoutParams(layoutParams);

footerHolder.txtTitleFooter.setText(“Footer”);

footerHolder.txtTitleFooter

.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

Toast.makeText(context, “Clicked Footer”,

Toast.LENGTH_SHORT).show();

}

});

}

else if (holder instanceof ContentsViewHolder) {

ContentsViewHolder contentsHolder = (ContentsViewHolder) holder;

StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

ViewGroup.LayoutParams.MATCH_PARENT);

layoutParams.setFullSpan(true);

ImageLoader imageLoader = ImageLoader.getInstance();

contentsHolder.countryName

.setText(itemList.get(position).getName());

// holder.countryPhoto.setImageResource(itemList.get(position).getPhoto());

imageLoader.displayImage(itemList.get(position).getPhoto_url(),

contentsHolder.countryPhoto, defaultOptions);

}

}

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.