Reputation: 5475
I know this issue has been discussed before, but I haven't found a suitable answer. I'd like to have a table with 3 rows and 2 columns. The left column would be a title, and the right column would be a list of items.
Hence I have 3 lists, one below the other, and I would like to make the whole screen scrollable (not each list scrollable separately).
The solution would be to use a ScrollView
as the main component, then a TableView
, then a ListView
in the right columns of the table. The problem is that ListView
is a scrollable component and won't work inside a ScrollView
.
My question - is there any component, be it part of Android API or third party, that has the ListView
functionality but is fixed size? I would like to enjoy the adapter functionality and the onItemClick()
functionality (that gives me the clicked item's position).
Thanks
Edit: I tried the suggestion to set the height of the ListView
manually, the result was that the area where the ListView
was supposed to be indeed expanded as necessary, but the list elements were not displayed.
I used the following code:
ListView lv = (ListView)view.findViewById(R.id.list);
lv.setAdapter(adapter);
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(lv.getLayoutParams());
lParams.height = calculateHeight(lv);
lv.setLayoutParams(lParams);
Without the last 3 lines it works just fine, but then the size is fixed, which brings me back to my original problem.
Upvotes: 0
Views: 1782
Reputation: 777
What i assume from your expectation is you are looking for
( Title, (ListView) )
( Title, (ListView) )
( Title, (ListView) )
If this is the what you are looking for, then you can use tableView as main layout, and you can make the listView not scrollable by giving its fixed height.
How to do it is, you need to measure the height of each child view's height and its divider height and set the listview's layout params to its exact height, then listview wont be scrollable, but the whole tableview is scrollable.
I would like you to take a look at this link. http://iserveandroid.blogspot.sg/2011/06/how-to-calculate-lsitviews-total.html
Once you set the layout as content view, you need to set the adapters to the listviews, and immediately you need to set the (calculated height)layoutparams to the listviews.
Upvotes: 2