2

listview scroll on some devices Nexus_5x and doesn't scroll on Samsung galaxy tab 7

I try everything on the internet :

this doesn't work !

// save index and top position
int index = mList.getFirstVisiblePosition();
View v = mList.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - mList.getPaddingTop());

// ...

// restore index and position
mList.setSelectionFromTop(index, top);

Link here

Maintain/Save/Restore scroll position when returning to a ListView

also this doesn't work

ListView lv = (ListView)findViewById(R.id.myListView);  // your listview inside scrollview
lv.setOnTouchListener(new ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

link here

ListView inside ScrollView is not scrolling on Android

My listView xml is

 <ListView
        android:id="@+id/listview"
        style="@style/ListView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginEnd="5dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="8dp"

        android:visibility="visible"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonClear"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

landscape doesn't work , but portrait is just fine.

I don't understand why it's ok on some devices and even portrait mode but not the other ?

Towfik Alrazihi
  • 490
  • 3
  • 8
  • 23

1 Answers1

2

To start with, its not always a good idea to nest a scrollable view in another especially when they are scrolling in the same direction, although in some cases there are not much alternatives. When I want to implement something like that say a recyclerview in a scrollview, I disable the scrolling behaviour of the recyclerview and make the size expand depending on the size of the contents

http://www.it1me.com/it-answers?id=33330388&ttl=How+to+put+RecyclerView+inside+NestedScrollView%3F

That is a link to where it is implemented. Study it so you'll get the idea. Goodluck

Odufuwa Segun
  • 274
  • 1
  • 9