-3

I have a main Layout including 2 layout, one containing a FrameLayout with a Fragment inside. And the other one with a LinearLayout containing a ListView. This is how look my main layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <include layout="@layout/map_layout" android:layout_height="wrap_content"  android:layout_width="fill_parent" android:layout_weight="1"></include>
            <include layout="@layout/list_layout" android:layout_height="wrap_content"  android:layout_width="fill_parent" android:layout_weight="6"></include>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

The first Fragment contain a map and the second contain a custom ListView with its own listAdapter.

So here my problem, I know it's kind of triky to put a ListView in a ScrollView. But in my onCreateView of my ListFragment.java I put this :

        list.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                v.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });

But the ListView keep catch the scroll. At a moment, the ScrollView bug and put the map and le list down of an infite ScrollView.

How can I do to make it work ?

Maregas
  • 11
  • 6
  • You're trying to do something that the platform does not support, and it's a well limitation of it (IT DEFO IS NOT A BUG) and it's not working. And what is your question? – Budius Aug 22 '15 at 14:54
  • How can I do to make it work ? – Maregas Aug 22 '15 at 15:09
  • You don't put a ScrollView inside a ListVIew, the platform does not support that. Try the CoordinatorLayout instead. – Budius Aug 22 '15 at 15:14
  • It's a ListView inside a ScrollView. But I will look How to use CoordinatorLayout. – Maregas Aug 22 '15 at 15:17
  • ListView inside ScrollVIew or ScrollView inside ListView makes no difference. None of them were made to support nested scrolling and nested scrolling does not work with them. – Budius Aug 22 '15 at 15:20

1 Answers1

0

I finally find the solution of my problem.

I needed to extend my listView so there its only scrolled by the ScrollView. here the code I find :

Helper.java:

public class Helper {
    public static void getListViewSize(ListView myListView) {
        ListAdapter myListAdapter = myListView.getAdapter();
        if (myListAdapter == null) {
        //do nothing return null
            return;
        }
    //set listAdapter in loop for getting final size
        int totalHeight = 0;
        for (int size = 0; size < myListAdapter.getCount(); size++) {
            View listItem = myListAdapter.getView(size, null, myListView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
  //setting listview item in adapter
        ViewGroup.LayoutParams params = myListView.getLayoutParams();
        params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
        myListView.setLayoutParams(params);
    }
}

and to implement it, you just need this line:

Helper.getListViewSize(myList);

I have found this solution here : http://www.androidhub4you.com/2012/12/listview-into-scrollview-in-android.html

Maregas
  • 11
  • 6