0

Previously I ran into a problem where my ListView located in a ViewPager wasn't scrolling. I managed to solve it with a bit of help from https://stackoverflow.com/a/24629341/3739429. Everything worked fine on my Nexus 6P, but then I tried to run it on my Lenovo P70-A an Error occurred (see title).

My CustomListView class:

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListView;

/**
 * Created by Daniel on 17-Mar-17.
 */

public class CustomScrollListView extends ListView {

public CustomScrollListView(Context context) {
    super(context);
}

public CustomScrollListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomScrollListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
    AbsListView.LayoutParams params = (AbsListView.LayoutParams) getLayoutParams();
    params.height = getMeasuredHeight();
}
}

It's erroring on this line of code:

super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);

and My xml where Im using it:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout   xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/containerView"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <uk.mygide.heyme.CustomScrollListView
        android:id="@+id/convList"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </uk.mygide.heyme.CustomScrollListView>

</android.support.v4.widget.NestedScrollView>

I have been looking at it for quite some time but can't seem to find the solution, any help? Thank you in advance.

Community
  • 1
  • 1
user6704969
  • 21
  • 1
  • 5
  • problem look like in this line ViewGroup.LayoutParams params = getLayoutParams(); – Jaydeep Devda Mar 18 '17 at 17:58
  • @JaydeepPatel, My logcat is pointing me to that one line...so yeah, not sure. Nevertheless, changing that to AbsListView.LayoutParams doesn't seem to be working either. – user6704969 Mar 18 '17 at 18:37

0 Answers0