My favorites
▼
|
Sign in
myandroidwidgets
Sample Apps for Android
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
CustomExpandableListView
/
src
/
com
/
beanie
/
example
/
list
/
SampleActivity.java
‹r15
r56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.beanie.example.list;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ExpandableListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import com.beanie.example.list.adapter.ExpandableListAdapter;
import com.beanie.example.list.classes.Vehicle;
import com.beanie.example.list.data.MockDataProvider;
public class SampleActivity extends Activity implements Runnable
{
private ExpandableListAdapter adapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Retrive the ExpandableListView from the layout
ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
listView.setOnChildClickListener(new OnChildClickListener()
{
@Override
public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, int arg3, long arg4)
{
Toast.makeText(getBaseContext(), "Child clicked", Toast.LENGTH_LONG).show();
return false;
}
});
listView.setOnGroupClickListener(new OnGroupClickListener()
{
@Override
public boolean onGroupClick(ExpandableListView arg0, View arg1, int arg2, long arg3)
{
Toast.makeText(getBaseContext(), "Group clicked", Toast.LENGTH_LONG).show();
return false;
}
});
// Initialize the adapter with blank groups and children
// We will be adding children on a thread, and then update the ListView
adapter = new ExpandableListAdapter(this, new ArrayList<String>(),
new ArrayList<ArrayList<Vehicle>>());
// Set this blank adapter to the list view
listView.setAdapter(adapter);
// This thread randomly generates some vehicle types
// At an interval of every 2 seconds
Thread thread = new Thread(this);
thread.start();
}
@Override
public void run()
{
final int ITEMS = 15;
int count = 0;
while (count != ITEMS)
{
count++;
adapter.addItem(MockDataProvider.getRandomVehicle("Vehicle no. " + count));
// Notify the adapter
handler.sendEmptyMessage(1);
try
{
// Sleep for two seconds
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
private Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
adapter.notifyDataSetChanged();
super.handleMessage(msg);
}
};
}
Show details
Hide details
Change log
r20
by coomar.101 on Oct 6, 2010
Diff
Items are clickable
Go to:
...example/list/SampleActivity.java
...apter/ExpandableListAdapter.java
Project members,
sign in
to write a code review
Older revisions
r15
by coomar.101 on Sep 16, 2010
Diff
Initial Commit
All revisions of this file
File info
Size: 3233 bytes, 107 lines
View raw file
Powered by
Google Project Hosting