Friday, March 23, 2012


ListView with Sections in android.-1


Today also we will see another customization of listviews.
Today I will show you how to create listviews with sections.
This is the main.xml layout file which contains the ListView.
?
Drag and copy the code
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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"
    android:background="@drawable/orange"
    >
    <ListView
            android:id="@+id/list1"
            android:cacheColorHint="#00000000"
            android:scrollbars="none"
            android:background="@drawable/bg_transparent"
            android:fadingEdge="vertical"
            android:soundEffectsEnabled="true"
            android:divider="@drawable/green"
            android:dividerHeight="1px"
            android:padding="0dip"
            android:smoothScrollbar="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="false"
            android:layout_marginTop="5dip"
            android:layout_marginLeft="5dip"
            android:layout_marginRight="5dip"
            android:layout_marginBottom="5dip"
            android:layout_weight="1"/>
 
</LinearLayout>
I am using some resources in this, one of which is the “customshape_header.xml” file which is saved in res/drawable directory.
This will ptovide the background for the section header.
customshape_header.xml
?
Drag and copy the code
1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
    <corners android:radius="3dp" />
    <solid android:color="#FFFFFF"/>
    <stroke
        android:width="1dip"
        android:color="#C0C0FF" />
</shape>
Strings.xml
?
Drag and copy the code
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">ListView with Sections</string>
    <drawable name="white">#ffffff</drawable>
    <drawable name="black">#000000</drawable>
    <drawable name="green">#347C2C</drawable>
    <drawable name="pink">#FF00FF</drawable>
    <drawable name="violet">#a020f0</drawable>
    <drawable name="grey">#778899</drawable>
    <drawable name="red">#C11B17</drawable>
    <drawable name="yellow">#FFFF8C</drawable>
    <drawable name="PowderBlue">#b0e0e6</drawable>
    <drawable name="brown">#2F1700</drawable>
    <drawable name="Hotpink">#7D2252</drawable>
    <drawable name="orange">#FFA500</drawable>
    <drawable name="darkgrey">#606060</drawable>
</resources>
This is the “lv_layout.xml” file which I am using for each row in the listview.
?
Drag and copy the code
1
2
3
4
5
6
7
8
<?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"
    android:id="@+id/l1"
    >
</LinearLayout>

No comments: