Skip to content

Instantly share code, notes, and snippets.

@oatpano
Last active September 25, 2016 06:51
Show Gist options
  • Save oatpano/bc162df4f0f2aeafbb037272056e733d to your computer and use it in GitHub Desktop.
Save oatpano/bc162df4f0f2aeafbb037272056e733d to your computer and use it in GitHub Desktop.
public class RecyclerViewAdapter extends RecyclerView.Adapter<DataObjectHolder> {
public RecyclerViewAdapter() {
}
@Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Timber.i("onCreateViewHolder");
View view = new ChatItemView(parent.getContext());
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(lp);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
@Override
public void onBindViewHolder(DataObjectHolder holder, int position) {
int viewHeight = chatItemView.getMeasuredHeight();
if (isShowEmptyView){
if (viewHeight < recyclerViewHeight){
chatItemView.setEmptyView(View.VISIBLE, recyclerViewHeight - viewHeight); //ผลลัพธ์ของ recyclerViewHeight - viewHeight ที่ค่า height ของ empty view
}
else{
chatItemView.setEmptyView(View.GONE, 0);
}
}
else{
chatItemView.setEmptyView(View.GONE, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment