Skip to content

Instantly share code, notes, and snippets.

@Avjeet
Created February 19, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avjeet/ebeb66fe4b9bfcf93adc2b477d1c0b27 to your computer and use it in GitHub Desktop.
Save Avjeet/ebeb66fe4b9bfcf93adc2b477d1c0b27 to your computer and use it in GitHub Desktop.
public class Holder extends RecyclerView.ViewHolder {
public TextView applicationName;
public ImageView applicationIcon;
public Holder(View itemView) {
super(itemView);
this.applicationName = (TextView) itemView.findViewById(R.id.application_name);
this.applicationIcon = (ImageView) itemView.findViewById(R.id.application_icon);
}
public void setup(final ApplicationItem applicationItem, final OnItemClickListener listener) {
applicationName.setText(applicationItem.getApplicationName());
Picasso.with(mContext).load(applicationItem.getApplicationIcon()).into(applicationIcon);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onItemClick(applicationItem);
}
});
}
}
public ApplicationAdapter(Context mContext, List<ApplicationItem> applicationList, OnItemClickListener listener) {
this.mContext = mContext;
this.applicationList = applicationList;
this.listener = listener;
if(mContext.getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT){
isPortraitMode=true;
}
}
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.application_list_item, parent, false);
if( isPortraitMode) {
height = ((View) parent.getParent()).getHeight();
}
Log.e("item","itemView created");
return new Holder(itemView);
}
@Override
public void onBindViewHolder(Holder holder, int position) {
if( isPortraitMode) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.height=height/3;
holder.itemView.setLayoutParams(params);
Log.e("item"+position,"item"+position+"binded");
}
holder.setup(applicationList.get(position), listener);
}
@Override
public int getItemCount() {
return applicationList.size();
}
public interface OnItemClickListener {
void onItemClick(ApplicationItem item);
}
}
@Avjeet
Copy link
Author

Avjeet commented Feb 19, 2018

but using this code I m getting only last two child views.
here is the logcat

captured

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment