Skip to content

Commit 3cb7990

Browse files
Initial commit
1 parent 9f3becb commit 3cb7990

File tree

28 files changed

+582
-0
lines changed

28 files changed

+582
-0
lines changed

ExpandableListView/.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>

ExpandableListView/.project

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>ExpandableListView</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.survivingwithandroid.expandablelistview"
3+
android:versionCode="1"
4+
android:versionName="1.0" >
5+
6+
<uses-sdk
7+
android:minSdkVersion="8"
8+
android:targetSdkVersion="15" />
9+
10+
<application
11+
android:icon="@drawable/ic_launcher"
12+
android:label="@string/app_name"
13+
android:theme="@style/AppTheme" >
14+
<activity
15+
android:name=".MainActivity"
16+
android:label="@string/title_activity_main" >
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Automatically generated file. DO NOT MODIFY */
2+
package com.survivingwithandroid.expandablelistview;
3+
4+
public final class BuildConfig {
5+
public final static boolean DEBUG = true;
6+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* AUTO-GENERATED FILE. DO NOT MODIFY.
2+
*
3+
* This class was automatically generated by the
4+
* aapt tool from the resource data it found. It
5+
* should not be modified by hand.
6+
*/
7+
8+
package com.survivingwithandroid.expandablelistview;
9+
10+
public final class R {
11+
public static final class attr {
12+
}
13+
public static final class drawable {
14+
public static final int ic_action_search=0x7f020000;
15+
public static final int ic_launcher=0x7f020001;
16+
}
17+
public static final class id {
18+
public static final int expandableListView1=0x7f070000;
19+
public static final int groupDescr=0x7f070002;
20+
public static final int groupName=0x7f070001;
21+
public static final int itemDescr=0x7f070004;
22+
public static final int itemName=0x7f070003;
23+
public static final int menu_settings=0x7f070005;
24+
}
25+
public static final class layout {
26+
public static final int activity_main=0x7f030000;
27+
public static final int group_layout=0x7f030001;
28+
public static final int item_layout=0x7f030002;
29+
}
30+
public static final class menu {
31+
public static final int activity_main=0x7f060000;
32+
}
33+
public static final class string {
34+
public static final int app_name=0x7f040000;
35+
public static final int hello_world=0x7f040001;
36+
public static final int menu_settings=0x7f040002;
37+
public static final int title_activity_main=0x7f040003;
38+
}
39+
public static final class style {
40+
public static final int AppTheme=0x7f050000;
41+
}
42+
}
36.2 KB
Loading
341 KB
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

ExpandableListView/project.properties

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-16
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent" >
5+
6+
<ExpandableListView
7+
android:id="@+id/expandableListView1"
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:layout_alignParentRight="true"
11+
android:layout_alignParentTop="true"
12+
android:layout_marginTop="10dp"
13+
>
14+
15+
</ExpandableListView>
16+
17+
</RelativeLayout>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent" >
5+
6+
<TextView
7+
android:id="@+id/groupName"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:paddingLeft="15dip" />
11+
12+
<TextView
13+
android:id="@+id/groupDescr"
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
android:layout_alignParentLeft="true"
17+
android:layout_below="@id/groupName"
18+
android:textSize="8dip" />
19+
20+
</RelativeLayout>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent" >
5+
6+
<TextView
7+
android:id="@+id/itemName"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:layout_alignParentLeft="true" />
11+
12+
<TextView
13+
android:id="@+id/itemDescr"
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
android:layout_alignParentLeft="true"
17+
android:layout_below="@id/itemName" />
18+
19+
</RelativeLayout>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
2+
<item android:id="@+id/menu_settings"
3+
android:title="@string/menu_settings"
4+
android:orderInCategory="100"
5+
android:showAsAction="never" />
6+
</menu>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
3+
<style name="AppTheme" parent="android:Theme.Holo.Light" />
4+
5+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
3+
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
4+
5+
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<string name="app_name">ExpandableListView</string>
4+
<string name="hello_world">Hello world!</string>
5+
<string name="menu_settings">Settings</string>
6+
<string name="title_activity_main">MainActivity</string>
7+
8+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
3+
<style name="AppTheme" parent="android:Theme.Light" />
4+
5+
</resources>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (C) 2013 Surviving with Android (http://www.survivingwithandroid.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.survivingwithandroid.expandablelistview;
18+
19+
import java.util.List;
20+
21+
import com.survivingwithandroid.expandablelistview.model.Category;
22+
import com.survivingwithandroid.expandablelistview.model.ItemDetail;
23+
24+
import android.content.Context;
25+
import android.view.LayoutInflater;
26+
import android.view.View;
27+
import android.view.ViewGroup;
28+
import android.widget.BaseExpandableListAdapter;
29+
import android.widget.ImageView;
30+
import android.widget.TextView;
31+
32+
public class ExpandableAdapter extends BaseExpandableListAdapter {
33+
34+
private List<Category> catList;
35+
private int itemLayoutId;
36+
private int groupLayoutId;
37+
private Context ctx;
38+
39+
public ExpandableAdapter(List<Category> catList, Context ctx) {
40+
41+
this.itemLayoutId = R.layout.item_layout;
42+
this.groupLayoutId = R.layout.group_layout;
43+
this.catList = catList;
44+
this.ctx = ctx;
45+
}
46+
47+
@Override
48+
public Object getChild(int groupPosition, int childPosition) {
49+
return catList.get(groupPosition).getItemList().get(childPosition);
50+
}
51+
52+
@Override
53+
public long getChildId(int groupPosition, int childPosition) {
54+
return catList.get(groupPosition).getItemList().get(childPosition).hashCode();
55+
}
56+
57+
@Override
58+
public View getChildView(int groupPosition, int childPosition,
59+
boolean isLastChild, View convertView, ViewGroup parent) {
60+
61+
View v = convertView;
62+
63+
if (v == null) {
64+
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService
65+
(Context.LAYOUT_INFLATER_SERVICE);
66+
v = inflater.inflate(R.layout.item_layout, parent, false);
67+
}
68+
69+
TextView itemName = (TextView) v.findViewById(R.id.itemName);
70+
TextView itemDescr = (TextView) v.findViewById(R.id.itemDescr);
71+
72+
ItemDetail det = catList.get(groupPosition).getItemList().get(childPosition);
73+
74+
itemName.setText(det.getName());
75+
itemDescr.setText(det.getDescr());
76+
77+
return v;
78+
79+
}
80+
81+
@Override
82+
public int getChildrenCount(int groupPosition) {
83+
int size = catList.get(groupPosition).getItemList().size();
84+
System.out.println("Child for group ["+groupPosition+"] is ["+size+"]");
85+
return size;
86+
}
87+
88+
@Override
89+
public Object getGroup(int groupPosition) {
90+
return catList.get(groupPosition);
91+
}
92+
93+
@Override
94+
public int getGroupCount() {
95+
return catList.size();
96+
}
97+
98+
@Override
99+
public long getGroupId(int groupPosition) {
100+
return catList.get(groupPosition).hashCode();
101+
}
102+
103+
@Override
104+
public View getGroupView(int groupPosition, boolean isExpanded,
105+
View convertView, ViewGroup parent) {
106+
107+
View v = convertView;
108+
109+
if (v == null) {
110+
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService
111+
(Context.LAYOUT_INFLATER_SERVICE);
112+
v = inflater.inflate(R.layout.group_layout, parent, false);
113+
}
114+
115+
TextView groupName = (TextView) v.findViewById(R.id.groupName);
116+
TextView groupDescr = (TextView) v.findViewById(R.id.groupDescr);
117+
118+
119+
Category cat = catList.get(groupPosition);
120+
121+
groupName.setText(cat.getName());
122+
groupDescr.setText(cat.getDescr());
123+
124+
return v;
125+
126+
}
127+
128+
@Override
129+
public boolean hasStableIds() {
130+
return true;
131+
}
132+
133+
@Override
134+
public boolean isChildSelectable(int groupPosition, int childPosition) {
135+
return true;
136+
}
137+
138+
}

0 commit comments

Comments
 (0)