list inside scrollview - android

On my screen I have a list view and a button. my list has like 8 item. I would like my screen to scroll if both these items does not fit in. I don't want my list to have scroll but the complete layout including both list & button. If I use the below layout it only shows on item inside the list and I have to scroll within the list to go to next item.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#android:id/list"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#drawable/round_background" />
<Button android:text="Search" android:id="#+id/carSearchButton"
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

You can't put a ListView inside a ScrollView. Of GridView, or whatever View that handles scrolling on the same axis as the ScrollView does. That way the framework wouldn't know which View should handle the scrolling event. This layout won't produce an error when you compile it, but it won't work properly.
What you should do here: dump the outer ScrollView, you don't need it. Only use a ListView, and add the button to the ListView, using .addFooter(), that's the easiest way. This way your button'll appear as a list element, but you don't have to mess around with a custom adapter.

Scythe kind of answers my question but I wanted more then one one control below the list also on another screen I wanted 2 lists. So in order to have the scroll bar working with list view I had to fix the height of the list.

Related

can i have a listview and an expandablelistview in the same view

I have several edittexts in my view for taking input for a database query .I'm displaying the query results in a list view below the edittextfields. Because there are 7 edittextfields there is not enough space for the listview. I wanted to put all the edittexts in an expandablelistview.
Problem i'm facing is -only the expandablelistview item is shown -the listview doesnt come up at all --i have #android:id/empty and #android:id/list entries ---but nothing comes up
i can't add the listview into the expandablelistview as that is not allowed + since i need both #android:id/empty and #android:id/list to show query results i need a proper list view.
what are my options --? i could ofcourse display the results in a separate window
If you could show the xml you have right now it would be great but the ideas behind it needs to be something like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Edit:
Okay so i figured out that for this layout to function correctly you need to set dome weight so that the linearlayout understand what size to give each children. Use:
android:layout_weight="1"
in the listview and the expandablelistview (1 in both means thay will divide space between them)

How to merge several ui elements into a listview in android?

I'm making a custom view which contains an ExpandableListView, a CheckedTextView and a ListView :
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/filtersDialogView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="200dp"
android:orientation="vertical" >
<ExpandableListView
android:id="#+id/filtersListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<CheckedTextView
android:id="#+id/onlyShowAvailableItemsCheckedTextView"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:text="#string/OnlyShowAvailableItems" />
<ListView
android:id="#+id/categoriesListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
The problem is that the CheckTextView is fixed and the two lists are scrolling independently (which is normal for that layout). Furthermore when I expand a list item from the ExpandableListView, the CheckedTextView and the other ListView become hidden. I'd like to make a single list with all these elements that could scroll and resize properly when I expand an element of the first list (the cells of the second list are not expandable). How can I do that? Is it possible to make it without having to modify the Adapters of the lists and the controller of the CheckedTextView ?
Thanks
How can I do that? Is it possible to make it without having to modify
the Adapters of the lists and the controller of the CheckedTextView ?
I doubt that, especially as you have two scrolling views, the ExpandableListView and the ListView. I think your only option is a special adapter that will simulate the layout above. I had a custom ExpandableListView adapter that I modified into something that will simulate the layout like the one above. It's something raw so there could be some errors(I've tested it a little) and of course there are other things to work on. The code sample it's a little big so I put it here https://gist.github.com/3046887 .

Scrolling up and down the ListView loses the top and bottom items in the list - Screenshot attached

I have an activity with the following items:
Action bar (one imageview, one view and two imagebutton) displayed on top of the activity, and for the rest of the screen I have one ListView. This is all placed in main.xml layout. The list will always have 6 rows no more and the action bar is not visible on this activity.
The listview loses text/images from some rows when scrolling up and down.
Before scrolling (I had to hide the logo though, sorry)
Before scrolling http://img706.imageshack.us/img706/37/32572081.png
After scrolling down and up (note DGL Lookup text disappear)
after first scrolling http://img638.imageshack.us/img638/7334/4scrollup.png
After scrolling down and up again (note DGL Lookup is still not there and Hazard Classes graphic and text disappear too
scrolling again and again http://img839.imageshack.us/img839/4970/5scrolldownagain.png
If I keep scrolling up and down, rows might show up again and might disappear as well.
here is my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
android:orientation="vertical" >
<include layout="#layout/action_bar" />
<ImageView
android:id="#+id/splashscreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
</ImageView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:textColor="#000" >
</ListView>
</LinearLayout>
Any quick help! I am very new to Android
#Frankenstein: Thanks for your help, you gave me the thread head and I followed it until the I got the solution.
The issue was that the listview display certain number of rows on a screen, and display more rows as you scroll up and down using getView method. The new rows displayed will normally take the style of the rows they are replacing.
So, if row1 has a different font style than others, then the row that will take it's place will inherit the same font style. What you may do, check if this is a different row that shouldn't inherit the style and then change the style to what you like.
Check this article http://android.amberfog.com/?p=296 which will explain what I just said in a technical way

How to make a section header in ListView which always sticks on top?

Android does not have a support for section headers on ListView by default. Based from my research, I've learned that there are 2 ways to implement a section header on ListView. The first one is to support 2 types of views in the list view: the separator view and the content view. The second one is to include a separator view in all of the content views and just set the visibility of the separator view to either VISIBLE or GONE. I'm using the second method.
However, when I scroll the ListView upwards, the section header is also scrolled up. I know this is normal. But I want the section header to remain on top as long as some data belonging to its section are still being displayed. The behavior that I want to accomplish is similar to the behavior of the section headers of UITableView in iOS. How can I accomplish this?
Also, I would like to note that I've read that one solution for this is to create a view above the ListView and just change it if needed. However, this won't work for all phones. For example, the ListView on Samsung phones are bouncing. If I placed a view above the ListView to act as header and the ListView bounces, the dummy header view won't bounce together with the ListView. Also, the top of the default ListView can easily be spotted because it glows when the ListView is being scrolled. Is there anyway to accomplish the said effect while making sure that it still looks natural?
The picture below shows the problem that I will be encountering if I just add a textview on top of the listview: (Taken from Samsung Galaxy S2)
see in this xml + symbol is static u will get some help
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearlayout">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#00ffff">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/plus" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>

How to add a fixed LinearLayout below a scrollable ListActivity

what is the easiest way of achieving the following please? I've got a ListActivity which lists a number of search results. The look of the results is an XML specified LinearLayout. The results can go into thousands so I display only a number at a time, say 100. To open next page of results the user needs to click the hardware menu button and click 'Next' from there. I would however like a fixed LinearLayout on the bottom of results with always always visible navigation buttons. How can I do this? Do I somehow nest the XML layouts? Thanks!
You should have something like this:
LinearLayout - vertical, fill_parent in height, and non-scrollable
LinearLayout - vertical, fill_parent in height, scrollable. this will hold the scrolling list
LinearLayout - horizontal, wrap_content in height
Use Something like below. instead of using menu to see next page records. use the last cell of list as view more record button and on click of that add new records and notify the dataset changed.
Search a free app by name starr partners over android market. on the 2nd screen of app you will see a search result list with header and view more records last cell..
Check the code below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_height="45dip" android:layout_alignParentTop="true"
android:background="#333333"
android:id="#+id/linearLayout1" android:layout_width="fill_parent"></LinearLayout>
<LinearLayout android:layout_height="45dip" android:layout_alignParentBottom="true"
android:background="#555555"
android:id="#+id/linearLayout2" android:layout_width="fill_parent"></LinearLayout>
<ListView android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="#+id/linearLayout1"
android:layout_above="#+id/linearLayout2"
android:background="#CCCCCC"
android:id="#+id/listView1"></ListView>
</RelativeLayout>
Hope this help :)

Categories

Resources