Android: Nested List Views and item heights - android

I am currently trying to create a nested ListView.
An outer ListView contains items, of which each consists of a TextView, as caption, and another ListView with children.
Filling the ListViews works really nice using another nested ListView adapter, yet, when it comes to actually displaying the content on the device, the nested list items are not high enough to display all the children. To be exact, only the first nested list item is displayed.
My current layout approach is the following:
Outer list item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5px"
>
<TextView android:id="#+id/day"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#ff5e00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollHorizontally="false"/>
<ListView android:id="#+id/innerList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fadingEdge="none"
/>
</LinearLayout>
and an inner list layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5px"
>
<TextView android:id="#+id/innertextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollHorizontally="false"
android:singleLine="false"/>
</LinearLayout>
Is there any chance to adapt the size of the outer list item in a way that all the inner list items will be displayed?
I also looked at ExpandableListViews. This approach worked, yet, I do not want to have the list items collapsed.
Thank you very much,
Matthias

I did not really like this solution, so I looked into this issue some more and found another solution:
ExpandableListView inherits from ListView. What it does is overriding the getView method from BaseAdapter and make a distinction between child and parent items. It is not a real nested list, but it flattens the list by using different layout items.
The same can be done for creating a NestedListView. Inherit from ListView and expect a self created adapter, which makes a distinction between child and parent layout items.
For each one return the appropriately filled layout items.
Done.

You should be able to make the items in an ExpandableListView uncollaposable. This is probably you best option. For instructions on how disable collapsing, checkout this SO Post.

Related

populate listview with multiple datasources

Is it possible to populate a the same listview with 4 different sources?
at the moment my design is a
textview
listview
textview
listview
what i dont like is the two listview scroll indepently so if the top one is almost empty i have alot of empty space on my screen,
if I dont set the top one to a fixed size and it is very full, the bottom one is not shown.
I would like to have one listview/scrollview so everything is arranged nicely indepent on how many entries are in either of the arrays i use to populate my listviews.
can that be done?
thanks
this is my xml as mention above
<TextView
android:id="#+id/gamesView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/top_btns"
android:gravity="center"
android:text="#string/gamesView"
android:textColor="#FFFFFF"/>
<ListView
android:id="#+id/gameslist"
android:layout_width="match_parent"
android:layout_height="260dip"
android:layout_below="#id/gamesView" />
<TextView
android:id="#+id/finishedGamesView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/gameslist"
android:gravity="center"
android:text="#string/endedGamesView"
android:textColor="#FFFFFF"/>
<ListView
android:id="#+id/finishedgameslist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/finishedGamesView" />

Display list of lists using mvxlistview

I want to display a list of lists My data is an ObservableCollection where the SomeClass has another ObservableCollection in it.
Here is the code:
This is the main list:
<Mvx.MvxListView
android:id="#+id/MenuList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource Path=Dishes"
local:MvxItemTemplate="#layout/menuitemtemplate"
android:background="#color/backgroundlightgray"
android:layout_weight="1" />
Here is the item template which has another list inside it
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Com.TasteITAndroidClient"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:gravity="right"
android:textSize="16dp"
android:textStyle="bold"
android:textColor="#ff000000"
android:background="#color/white"
android:padding="10dp" />
<Mvx.MvxListView
android:id="#+id/CategoryDishes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Path=Items"
local:MvxItemTemplate="#layout/userpagedishtemplate"
style="#style/ToolBarImage"
android:background="#color/backgroundlightgray"
android:layout_below="#+id/textView1"
android:layout_marginTop="5dp" />
The userpagedishtemplate displays the item.
Basically it works but I am getting very small sized lists which show 1-2 items although I specified height=wrap_content on the subList.
Have I missed something? should I be doing something else?
Thanks
Amit
Placing a ListView that scrolls vertically inside another ListView which scrolls vertically is likely to cause touch area confusion for your users - which list scrolls...
If you really want a list within a list then you cab use the layout you've started on - but you will probably need to give the inner lists some assistance with their vertical sizing - something more than wrap_content
Alternatively, for very small inner lists, you could consider switching to MvxLinearLayout.
Alternatively, you could consider making the inner lists scroll horizontally.
Alternatively, you could consider collapsing your lists into a single list using a polymorphic-aware adapter to determine whether to show a header cell or an inner cell.

Horizontal scroll in android listView

I want to create list view, with ability to scrool horizontaly and vertically.
Image shows row item from list view.
Everything should act as normal list view - ability to scroll verticaly.
Besides Title ( Teszt Elk Nev ) rest data in row should also scrool horizontaly. ( as you can see on image - second row )
When I scroll horizontaly all rows in list view should scrool horizontaly, so all rows has the same horizontaly scrool position.
I spent few hours try to solve it. Best solution so far is horizontal scrool only one row.
My code for row item layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginRight="30dp"
android:text="one" />
<com.example.testproject.CustomHorScroll
android:id="#+id/myHorScroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/myLay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="70dp"
android:text="two" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="70dp"
android:text="three" />
<!-- rest items goes here --!>
</LinearLayout>
</com.example.testproject.CustomHorScroll>
</LinearLayout>
I want to handle horizontal scrool movement and propagate to all row in listview to set horizontalscroolView.scrolBy(x,0).
But I can't make it works. :/
Another idea is to skip listview and create custom layout with scroll view and horizontalScroll.
Unfortunately, Android doesn't support scrolling items within scrolling items generally speaking.
Your best bet is probably to use something such as a ScrollView or a HorizontalScrollView, and a LinearLayout containing lists (or other scrollable items) inside of that: http://developer.android.com/reference/android/widget/ScrollView.html
You probably want to look into use the two way listview library.
https://github.com/lucasr/twoway-view

Android: I have a fixed header for a listview but the "glow effect" is only for the listview

I'm trying to make a layout similar to the people app, so I have a list with a fixed header at the top. I define the header on top of the listview inside a relative layout but the "glow effect" at the top of the list is only for the listview and not the whole layout.
This is what I have:
and this is what I want:
This is my layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:minHeight="20dp"
android:orientation="vertical" >
<TextView
android:id="#+id/status_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/last_updated"
android:textSize="12sp"
android:textStyle="bold"
android:textAllCaps="true"
android:gravity="center|left"
android:layout_marginLeft="20dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:textColor="#color/nice_blue"
/>
<View style="#style/HeaderDivider"/>
</LinearLayout>
<ListView
android:id="#+id/status_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:headerDividersEnabled="false"
android:footerDividersEnabled="false"
android:layout_below="#+id/header_layout" >
</ListView>
The glow effect in both examples are functioning the same.
What is happening within the People application is that it is also a ListView just like yours. The effect happens in the same place. The Me, #, A, etc headers are actually inside the ListView.
Option 1
To do what you are looking to do, put a header in the ListView, you'll also need to create a custom ListView. This means extending ListView.
It sounds more challenging than it is, but you should be able to find a number of examples online. Look for examples that extend a ListView rather than creating a custom ListView.
The general idea is that you'll add in a TextView into the the View of the ListView that will act as your header. This will put the header text Last updated at inside of the ListView view that you've created and since it is inside, it will be included underneath the glow.
Option 2
You may be able to use the addHeaderView(View v, Object data, boolean isSelectable) or addHeaderView(View v) methods on the ListView itself.
I believe this will add a header row inside the ListView, but I've never used this so I can't say for sure how it works. This may be easier, but will be less flexible.

Android layout - listview and edittext below

I'm trying to mimic the behaviour of the HTC SMS application (tradional view), where all messages are shown, and an EditTextis shown below. As you can see in the screenshot, when scrolling upwards, the EditText scrolls away at the bottom.
I'm stuck with this, even after reading multiple posts (eg Android Layout with ListView and Buttons and this website: http://www.finalconcept.com.au/article/view/android-keeping-buttons-visible), it's not working as expected.
Thanks to the comments and EditText now showing under ListView, I've managed to have my ListView take all available space and start scrolling once completed. The EditText is showing at the bottom of the screen now - always. I'd like it to disappear at the bottom when I scroll up though - now it remains at the bottom
Current Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#android:id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TableLayout
android:layout_weight="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<EditText android:id="#+id/newmessagecontent"
android:layout_height="150dp"
android:singleLine="false"
android:gravity="top"
android:layout_width="250dp"
android:layout_alignParentTop="true"
/>
<Button android:layout_height="wrap_content"
android:id="#+id/sendmessage"
android:text="Send"
android:layout_width="wrap_content"
/>
</TableRow>
</TableLayout>
</LinearLayout>
i think what you need to implement here is some sort of modification of the SeparatedListAdapter from Jeff Sharkey from this Article. In this article he not only manages to add two Adapters to a ListView but also explains how to have Headers to separate them if you want (you can remove that part of the code).
So what i mean, is your first Adapter will be the data with It's rows, and the second Adapter will be a dummy one with no data that just points to a View with your controls or whatever.
this way the ListView and what you want to add at the bottom are gonna be all scrollable.
Hope this helps.
A ListView automatically scrolls if all the items in it take up more space than the view provides. What happens if you remove the ScrollView?

Categories

Resources