Sectioned ListView and ExpandableListView - android

I need to create a layout with a title bar on the top and a list view with n sections. The
list header of every section has got two distinct Buttons that must be clickable and focusable independently from each other. This is the code of the layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/title_bar" />
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
/>
</LinearLayout>
I tried this two solutions but I've found issues that I am not able to solve in both:
1) Using a sectioned adapter (source code can be found here). It works fine without the title bar but with the title bar the default focus algorithm doesn't work any more.
2) Using an ExpandableListAdapter (in this case obviously the ListView in the layout becomes an ExpandableListView). It works fine but if I press the dpad center button on group layout both buttons are clicked. I did not find a way to solve this.
Anyone can help?
Thanks very much!

How about trying Merge adapter https://github.com/commonsguy/cwac-merge it allows you to add multiple list and buttons !!

Related

Android - Creating a List like the Grocery IQ List

(Using Android version 4.0.4)
I'm trying to build functionality very similar to the list found on the GroceryIQ app:
I can create a nice looking list using the ExpandableListView shown in the xml below and a custom class that extends BaseExpandableListAdapter, but I'm having trouble with the second list. Is it two lists with a view in between? Could this be just one list with a special list divider that just looks like a bar?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ExpandableListView
android:id="#+id/ExpList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#null"
android:dividerHeight="5dp"
android:groupIndicator="#null"
android:paddingBottom="60dp" />
<include
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
layout="#layout/bottom_bar_list" />
</RelativeLayout>
I've tried adding another list, but two lists on one view don't seem to cooperate too well-- either the first list is chopped off or the second list doesn't show.
Thanks for your thoughts!
So, I don't know that it's possible to know exactly how Grocery IQ crafted their list, but I found that I could replicate a pretty similar list by super-customizing the ExpandableListView.
An ExpandableListView is implemented using custom Group Items and Child Items.
I added a relative layout to the Group Item that looked like the "awesome bar". Then programmatically when I populated my list, I had a "rogue" Group Item that when I found it, I would show the "awesome bar" instead of the regular group-- in all the other cases the relative layout was set to invisible.
It took a while to get it "just right" and my solution seems a little like a hack, but that's the gist of what worked for me.

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 does overlaying views work in Android?

In Android, i noticed that you can have a fixed view on top of another. For example, when you open your browser, and tap the search box, a keyboard prompt pops up (on top of a listview). However, notice that you can still scroll up and down on the listview without the keyboard going away. Like:
would someone please explain (preferrably some sample code in addition) how this works?
What i'm trying to do is just have a custom listview that always has a floating navigation bar on top of the listview and also on the bottom of the list view (it's not actually a header/footer of the listview, it's more like a header/footer of the screen). It would be similar to the example i just described, where the user can interact with both the navigation bar as well as the listview "underneath" the nav bar.
I am somewhat new to Android development, so please be nice and provide a little bit of details if you would :) much thanks in advance!!
whoops. looks like someone had a similar issue:
Layout Layers? Z-Axis?
and this post http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html explains how FrameLayout works and also how works, which is an even better alternative.
FrameLayout lays object in a different Z-axis, so this is the solution i was looking for.
There are many ways to achieve that, the simpler i can think of is using linear layout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/header">
//Here you add whatever you want in your "header"
</LinearLayout>
//create your listview
<ListView
android:id="#+id/content_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:layout_marginRight="10dip"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:scrollbars="none"
android:paddingBottom="5dp"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/footer">
//Here you add whatever you want in your "footer"
</LinearLayout>

list inside scrollview

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.

Categories

Resources