Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky grid header not working on some Android version

I am using Sticky grid header with below app Gradle dependencies.

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.tonicartos:stickygridheaders:1.0.1'
    testCompile 'junit:junit:4.12'

}

And build tool version are

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.stickyheader"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 8
        versionName '3'
        multiDexEnabled true
    }

 }

Curruntly Using android studio 2.2.3. before I update Android studio it works fine for all device, also below kitkat version. In some Devices Specifically below kitkat it crash and above kitkat version Code is workling fine.

In Below version of kitkat device I got This Error, Stack trace

04-14 10:32:13.520 24869-24869/com.example.stickyheader E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.stickyheader/com.example.stickyheader.CustomerEventDetailActivity}: android.view.InflateException: Binary XML file line #62: Error inflating class com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092) at android.app.ActivityThread.access$600(ActivityThread.java:133) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4794) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #62: Error inflating class com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698) at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) at android.view.LayoutInflater.inflate(LayoutInflater.java:489) at android.view.LayoutInflater.inflate(LayoutInflater.java:396) at android.view.LayoutInflater.inflate(LayoutInflater.java:352) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)

In Addition This is my Xml Code for Sticky grid header.

 <com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/gridViewCustomer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:animateLayoutChanges="true"
        android:choiceMode="singleChoice"
        android:columnWidth="250dp"
        android:fastScrollEnabled="true"
        android:horizontalSpacing="1dp"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"
        android:verticalSpacing="5dp"/>

It seems like It will Give Error because of appCompact version which is defind in dependances in build.gradle (I am not sure) .

enable to handle this error.

I also try to comment this dependancy

 compile 'com.android.support:appcompat-v7:25.3.1'

but not working.

Thank You :)

like image 554
Learning Always Avatar asked Apr 14 '17 09:04

Learning Always


3 Answers

It seems a library issue. Also the stacktrace you have posted does not have any info about the crash reason.
The library you are using is very old and abandoned . Read ReadME.MD.

So there is no support from the developer of this library its useless to open a issue . you should try some other solution . You can try This one or similar with RecyclerView and GridLayoutmanager.

like image 196
ADM Avatar answered Oct 27 '22 11:10

ADM


Try using this, its not that old and should work fine with appcompat

firstly add this dependency

compile 'com.codewaves.stickyheadergrid:stickyheadergrid:0.9.6'
  1. Implement an adapter by subclassing StickyHeaderGridAdapter
  2. Create holder class for each header and item type. Use HeaderViewHolder and ItemViewHolder as base classes.
  3. Override and implement getSectionCount(), getSectionItemCount(int section), onCreateHeaderViewHolder(ViewGroup parent, int headerType), onCreateItemViewHolder(ViewGroup parent, int itemType), onBindHeaderViewHolder(HeaderViewHolder viewHolder, int section), onBindItemViewHolder(ItemViewHolder viewHolder, int section, int offset).
  4. Create a StickyHeaderGridLayoutManager with required column count and assign it to your RecyclerView.
  5. Use only StickyHeaderGridAdapter::notify* methods

Hope this helps.

like image 38
Kashif K. Avatar answered Oct 27 '22 09:10

Kashif K.


It looks like you are using this library: https://github.com/TonicArtos/StickyGridHeaders.

Add it to you dependencies:

dependencies {
   compile "com.tonicartos:stickygridheaders:1.0.1"
}
like image 23
Jared Burrows Avatar answered Oct 27 '22 11:10

Jared Burrows