I have an existing adapter class which have android.support.v7.widget.RecyclerView and android.support.design.widget.AppBarLayout inside a android.support.design.widget.CoordinatorLayout parent. See below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/background_grey"
style="@style/layoutParent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_red_blue_gradient"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="@dimen/_8sdp"
android:paddingStart="@dimen/_8sdp"
android:paddingRight="@dimen/_8sdp"
android:paddingEnd="@dimen/_8sdp"
app:layout_collapseMode="none"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<com.android.somecustomlayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<com.android.someothercustomlayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/_5sdp"
android:layout_marginLeft="@dimen/_5sdp"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginRight="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:layout_marginBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
This is the code of adapter class
public class ABC extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private ArrayList<ResultModel> mResultModel;
private Context mContext;
public ABC (Context context, ArrayList<ResultModel> resultModel) {
mContext = context;
this.mResultModel = resultModel;
mParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View headerView = LayoutInflater.from(parent.getContext()).inflate(R.layout.abc, parent, false);
return new RowItemViewHolder(headerView);
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
RowItemViewHolder rowItemViewHolder = (RowItemViewHolder) holder;
rowItemViewHolder.textview.settext(mResultModel.get(position).mName.get(0));
// computations and logic for views
}
@Override
public int getItemCount() {
if (null != ResultModel) {
return mResultModel.size();
} else {
return 0;
}
}
}
@Override
public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder) {
super.onViewDetachedFromWindow(holder);
holder.itemView.clearAnimation();
}
private static class RowItemViewHolder extends RecyclerView.ViewHolder {
private textview textview1;
.....
RowItemViewHolder(View itemView) {
super(itemView);
textview = (textview) itemView.findViewById(R.id.some_id_here);
}
/**
* Method help to set listener on {@link ResultRowItemListener}
*
* @param itemListener instance of {@link ResultRowItemListener}
*/
public void setResultRowItemListener(ResultRowItemListener itemListener) {
mRowItemClickListener = itemListener;
}
/**
* Listener that provide method on row item click
*/
public interface FlightSearchResultRowItemListener {
void onResultRowItemClick(ResultModel ResultModel, int position);
}
}
Everything was working fine until I updated compileSdkVersion from 23 to 27. Also i updated buildToolsVersion, com.android.support:appcompat-v7, com.android.support:support-v4, com.android.support:design, com.android.support:cardview-v7,com.android.support:recyclerview-v7 to 27.1.1.
See the build.gradle below
apply plugin: 'com.android.library'
repositories {
maven { url 'http://repo1.maven.org/maven2' }
jcenter { //noinspection GroovyAssignabilityCheck
url 'http://jcenter.bintray.com/' }
}
android {
signingConfigs {
release {
keyAlias
keyPassword
storeFile file('')
storePassword ''
}
debug {
keyAlias
keyPassword
storeFile file('')
storePassword ''
}
}
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 17
targetSdkVersion 27
signingConfig signingConfigs.release
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
testCompile 'junit:junit:4.12'
//noinspection GradleCompatible,GradleDependency
compile 'com.android.support:appcompat-v7:27.1.1'
//noinspection GradleDependency
compile 'com.android.support:support-v4:27.1.1'
//noinspection GradleDependency
compile 'com.android.support:design:27.1.1'
//noinspection GradleDependency
compile 'com.android.support:cardview-v7:27.1.1'
//noinspection GradleDependency
compile 'com.android.support:recyclerview-v7:27.1.1'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.8.3'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.3'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.google.android.gms:play-services-auth:15.0.1'
compile 'com.google.firebase:firebase-core:16.0.1'
compile 'com.android.support:multidex:1.0.3'
implementation 'br.com.simplepass:loading-button-android:1.14.0'
}
After this my recyclerview is rendered blank. When I tried to debug the adapter class, only the constructor of the class is called and debug never reaches to any of the adapter methods like onCreateViewHolder & onBindViewHolder.
After some investigation, i come to few conclusion I like to share:
- If in the adapter layout, for RecyclerView if i change width and height to lets say 500dp each, I can see the list but not when they are match_parent.
- If instead of CoordinatorLayout as parent, i changed to Relativelayout, the listview is visible but not with CoordinatorLayout .
I have already looked into other solutions like Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,
But they are not helping as problem is only appearing after updating compilesdkversion to 27.