0

I've got a LinearLayout which includes among others two ListViews. Each ListView has it's own ArrayAdapter. Now the Scrolling shouldn't be in the ListViews, the user should see the whole Lists and scroll the whole view. Sourrounding the LinearLayout with a ScrollView doesn't work because of the inerhit Scrolling Views... .

How can I expand the ListViews and let the user scroll only the outer view?

lis
  • 670
  • 1
  • 13
  • 32

4 Answers4

2

You should not use a ListView this way.

List Views are meant to recycle views, which it cannot do if its not the view that is scrolling.

You could simply use a LinearLayout and add every single view to the layout. This would be better than using a ListView.

(This does not mean it is the best solution)

Chris K.
  • 1,060
  • 8
  • 10
  • therefore I have to create each views programmatically? Or is there a way to use the ArrayAdapter furthermore? – lis Sep 17 '15 at 14:39
  • yeah, it works! I found an example how to use the ArrayAdapter with a LinearLayout here: http://stackoverflow.com/a/12405779/2186109 – lis Sep 17 '15 at 15:13
1

This can be done easily in RecyclerView. But in this case you are using ListViews so try listView.setScrollContainer(false); may be it works for you

Umer
  • 1,566
  • 2
  • 20
  • 31
1

You should inflate Views Like this.

// from content View of activity or fragment
    listView = (LinearLayout) findViewById(R.id.sos_list_view);

    listView.removeAllViews();
    List<SosObject> sosList = batabase.getAllItems();

            for(SosObject t: sosList) {
                LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

// Item layout 
                View view = inflater.inflate(R.layout.sos_prewivew_item, null);

                TextView comment = (TextView) view.findViewById(R.id.sos_comment_text);
                TextView date = (TextView) view.findViewById(R.id.sos_date_text);
                TextView id = (TextView) view.findViewById(R.id.sos_answer_id);
                TextView tittle = (TextView) view.findViewById(R.id.answer_tittle);

                listView.addView(view);
            }
        }

Your xml Should look like:

<ScrollView> 
    <LinearLayout>
          </LinearLayout > // Fist list
          </LinearLayout > // Second list
    </LinearLayout>
</ScrollView>
Alpha
  • 1,754
  • 3
  • 21
  • 39
  • sorry, can you expand your code? What's sosList, DaAns, SosObjects, ...? – lis Sep 17 '15 at 14:49
  • there is no need for that. basically that's one of my apps code segement. SosObject is instance of object that you want to display. It's one list item. I edited code for better understanding. – Alpha Sep 18 '15 at 13:36
0

ListViews cannot be overriden to lose the scrolling ability. They seem to be designed as top-level objects that occupy the whole screen.
So basically you have 2 options here:

  • Convert all your elements into ListView's items
  • use LinearLayouts instead of ListViews and wrap all elements in a ScrollView
injecteer
  • 20,038
  • 4
  • 45
  • 89