0% found this document useful (0 votes)
67 views16 pages

Android Expandable List View Tutorial: July 27, 2013 08:32 PM

Expandable list view is used to group list data by categories. It has the capability of expanding and collapsing the groups when user touches header.

Uploaded by

habaoanh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views16 pages

Android Expandable List View Tutorial: July 27, 2013 08:32 PM

Expandable list view is used to group list data by categories. It has the capability of expanding and collapsing the groups when user touches header.

Uploaded by

habaoanh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

July 27, 2013 08:32 PM

Android Expandable List View Tutorial


33 Comments
Like 238 Tw eet 7

Expandable list view is used to group list data by categories. It has the capability of expanding and collapsing the groups when user touches header. If you are not aware of list view before please refer to this tutorial Android ListView Tutorial

Lets start by creating a new project.. 1. Create a new project in the Eclipse IDE from File Android Application Project and fill all required details. I left my main activity name as MainActivity.java 2. In order to create an expandable list view, we need three xml layout files. First one is for main listview, 2nd one for list view group item and 3rd one is for list view child item. Open your activity_main.xml and add ExpandableListView element.

a c t i v i t y _ m a i n . x m l
< ? x m lv e r s i o n = " 1 . 0 "e n c o d i n g = " u t f 8 " ? > < L i n e a r L a y o u tx m l n s : a n d r o i d = " h t t p : / / s c h e m a s . a n d r o i d . c o m / a p k / r e s / a n d r o i d " a n d r o i d : l a y o u t _ w i d t h = " f i l l _ p a r e n t " a n d r o i d : l a y o u t _ h e i g h t = " f i l l _ p a r e n t " a n d r o i d : o r i e n t a t i o n = " v e r t i c a l " a n d r o i d : b a c k g r o u n d = " # f 4 f 4 f 4 "> < E x p a n d a b l e L i s t V i e w a n d r o i d : i d = " @ + i d / l v E x p " a n d r o i d : l a y o u t _ h e i g h t = " m a t c h _ p a r e n t " a n d r o i d : l a y o u t _ w i d t h = " m a t c h _ p a r e n t " / > < / L i n e a r L a y o u t >

3. Create another xml layout for list view group header. I created an xml file named list_group.xml and pasted following code.

l i s t _ g r o u p . x m l
< ? x m lv e r s i o n = " 1 . 0 "e n c o d i n g = " u t f 8 " ? > < L i n e a r L a y o u tx m l n s : a n d r o i d = " h t t p : / / s c h e m a s . a n d r o i d . c o m / a p k / r e s / a n d r o i d " a n d r o i d : l a y o u t _ w i d t h = " f i l l _ p a r e n t " a n d r o i d : l a y o u t _ h e i g h t = " w r a p _ c o n t e n t " a n d r o i d : o r i e n t a t i o n = " v e r t i c a l " a n d r o i d : p a d d i n g = " 8 d p " a n d r o i d : b a c k g r o u n d = " # 0 0 0 0 0 0 " > < T e x t V i e w a n d r o i d : i d = " @ + i d / l b l L i s t H e a d e r " a n d r o i d : l a y o u t _ w i d t h = " f i l l _ p a r e n t " a n d r o i d : l a y o u t _ h e i g h t = " w r a p _ c o n t e n t " a n d r o i d : p a d d i n g L e f t = " ? a n d r o i d : a t t r / e x p a n d a b l e L i s t P r e f e r r e d I t e m P a d d i n g L e f t " a n d r o i d : t e x t S i z e = " 1 7 d p " a n d r o i d : t e x t C o l o r = " # f 9 f 9 3 d "/ > < / L i n e a r L a y o u t >

4.Create one more xml file named list_item.xml for child list item. This will contain simple TextView element.

l i s t _ i t e m . x m l
< ? x m lv e r s i o n = " 1 . 0 "e n c o d i n g = " u t f 8 " ? > < L i n e a r L a y o u tx m l n s : a n d r o i d = " h t t p : / / s c h e m a s . a n d r o i d . c o m / a p k / r e s / a n d r o i d " a n d r o i d : l a y o u t _ w i d t h = " m a t c h _ p a r e n t " a n d r o i d : l a y o u t _ h e i g h t = " 5 5 d i p " a n d r o i d : o r i e n t a t i o n = " v e r t i c a l "> < T e x t V i e w a n d r o i d : i d = " @ + i d / l b l L i s t I t e m " a n d r o i d : l a y o u t _ w i d t h = " f i l l _ p a r e n t " a n d r o i d : l a y o u t _ h e i g h t = " w r a p _ c o n t e n t " a n d r o i d : t e x t S i z e = " 1 7 d i p " a n d r o i d : p a d d i n g T o p = " 5 d p " a n d r o i d : p a d d i n g B o t t o m = " 5 d p " a n d r o i d : p a d d i n g L e f t = " ? a n d r o i d : a t t r / e x p a n d a b l e L i s t P r e f e r r e d C h i l d P a d d i n g L e f t " < / L i n e a r L a y o u t >

5. I am using a custom adapter class to create list view. Create a new class file called ExpandableListAdapter.java and extend this from BaseExpandableListAdapter . This class provides required methods to render listview.

getGroupView() Returns view for the list group header getChildView() Returns view for list child item

E x p a n d a b l e L i s t A d a p t e r . j a v a
p a c k a g ei n f o . a n d r o i d h i v e . e x p a n d a b l e l i s t v i e w ; i m p o r tj a v a . u t i l . H a s h M a p ; i m p o r tj a v a . u t i l . L i s t ; i m p o r ta n d r o i d . c o n t e n t . C o n t e x t ; i m p o r ta n d r o i d . g r a p h i c s . T y p e f a c e ; i m p o r ta n d r o i d . v i e w . L a y o u t I n f l a t e r ; i m p o r ta n d r o i d . v i e w . V i e w ; i m p o r ta n d r o i d . v i e w . V i e w G r o u p ; i m p o r ta n d r o i d . w i d g e t . B a s e E x p a n d a b l e L i s t A d a p t e r ; i m p o r ta n d r o i d . w i d g e t . T e x t V i e w ; p u b l i cc l a s sE x p a n d a b l e L i s t A d a p t e re x t e n d sB a s e E x p a n d a b l e L i s t A d a p t e r{ p r i v a t eC o n t e x t_ c o n t e x t ; p r i v a t eL i s t < S t r i n g >_ l i s t D a t a H e a d e r ;/ /h e a d e rt i t l e s / /c h i l dd a t ai nf o r m a to fh e a d e rt i t l e ,c h i l dt i t l e p r i v a t eH a s h M a p < S t r i n g ,L i s t < S t r i n g > >_ l i s t D a t a C h i l d ; p u b l i cE x p a n d a b l e L i s t A d a p t e r ( C o n t e x tc o n t e x t ,L i s t < S t r i n g >l i s t D a t a H e a d e r , H a s h M a p < S t r i n g ,L i s t < S t r i n g > >l i s t C h i l d D a t a ){ t h i s . _ c o n t e x t=c o n t e x t ; t h i s . _ l i s t D a t a H e a d e r=l i s t D a t a H e a d e r ; t h i s . _ l i s t D a t a C h i l d=l i s t C h i l d D a t a ; } @ O v e r r i d e p u b l i cO b j e c tg e t C h i l d ( i n tg r o u p P o s i t i o n ,i n tc h i l d P o s i t i t o n ){ r e t u r nt h i s . _ l i s t D a t a C h i l d . g e t ( t h i s . _ l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) ) . g e t ( c h i l d P o s i t i t o n ) ; } @ O v e r r i d e p u b l i cl o n gg e t C h i l d I d ( i n tg r o u p P o s i t i o n ,i n tc h i l d P o s i t i o n ){ r e t u r nc h i l d P o s i t i o n ; } @ O v e r r i d e p u b l i cV i e wg e t C h i l d V i e w ( i n tg r o u p P o s i t i o n ,f i n a li n tc h i l d P o s i t i o n , b o o l e a ni s L a s t C h i l d ,V i e wc o n v e r t V i e w ,V i e w G r o u pp a r e n t ){ f i n a lS t r i n gc h i l d T e x t=( S t r i n g )g e t C h i l d ( g r o u p P o s i t i o n ,c h i l d P o s i t i o n ) ; i f( c o n v e r t V i e w= =n u l l ){ L a y o u t I n f l a t e ri n f a l I n f l a t e r=( L a y o u t I n f l a t e r )t h i s . _ c o n t e x t . g e t S y s t e m S e r v i c e ( C o n t e x t . L A Y O U T _ I N F L A T E R _ S E R V I C E ) ; c o n v e r t V i e w=i n f a l I n f l a t e r . i n f l a t e ( R . l a y o u t . l i s t _ i t e m ,n u l l ) ; } T e x t V i e wt x t L i s t C h i l d=( T e x t V i e w )c o n v e r t V i e w . f i n d V i e w B y I d ( R . i d . l b l L i s t I t e m ) ;

t x t L i s t C h i l d . s e t T e x t ( c h i l d T e x t ) ; r e t u r nc o n v e r t V i e w ;

@ O v e r r i d e p u b l i ci n tg e t C h i l d r e n C o u n t ( i n tg r o u p P o s i t i o n ){ r e t u r nt h i s . _ l i s t D a t a C h i l d . g e t ( t h i s . _ l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) ) . s i z e ( ) ; } @ O v e r r i d e p u b l i cO b j e c tg e t G r o u p ( i n tg r o u p P o s i t i o n ){ r e t u r nt h i s . _ l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) ; } @ O v e r r i d e p u b l i ci n tg e t G r o u p C o u n t ( ){ r e t u r nt h i s . _ l i s t D a t a H e a d e r . s i z e ( ) ; } @ O v e r r i d e p u b l i cl o n gg e t G r o u p I d ( i n tg r o u p P o s i t i o n ){ r e t u r ng r o u p P o s i t i o n ; } @ O v e r r i d e p u b l i cV i e wg e t G r o u p V i e w ( i n tg r o u p P o s i t i o n ,b o o l e a ni s E x p a n d e d , V i e wc o n v e r t V i e w ,V i e w G r o u pp a r e n t ){ S t r i n gh e a d e r T i t l e=( S t r i n g )g e t G r o u p ( g r o u p P o s i t i o n ) ; i f( c o n v e r t V i e w= =n u l l ){ L a y o u t I n f l a t e ri n f a l I n f l a t e r=( L a y o u t I n f l a t e r )t h i s . _ c o n t e x t . g e t S y s t e m S e r v i c e ( C o n t e x t . L A Y O U T _ I N F L A T E R _ S E R V I C E ) ; c o n v e r t V i e w=i n f a l I n f l a t e r . i n f l a t e ( R . l a y o u t . l i s t _ g r o u p ,n u l l ) ; } T e x t V i e wl b l L i s t H e a d e r=( T e x t V i e w )c o n v e r t V i e w . f i n d V i e w B y I d ( R . i d . l b l L i s t H e a d e r ) ; l b l L i s t H e a d e r . s e t T y p e f a c e ( n u l l ,T y p e f a c e . B O L D ) ; l b l L i s t H e a d e r . s e t T e x t ( h e a d e r T i t l e ) ; } r e t u r nc o n v e r t V i e w ;

@ O v e r r i d e p u b l i cb o o l e a nh a s S t a b l e I d s ( ){ r e t u r nf a l s e ; } @ O v e r r i d e p u b l i cb o o l e a ni s C h i l d S e l e c t a b l e ( i n tg r o u p P o s i t i o n ,i n tc h i l d P o s i t i o n ){ r e t u r nt r u e ; }

6. Once you are done with customer adapter, open your MainActivity.java and do the following

changes. In the following I created required data needed for list view and passed it to custom adapter.

M a i n A c t i v i t y . j a v a
p a c k a g ei n f o . a n d r o i d h i v e . e x p a n d a b l e l i s t v i e w ; i m p o r tj a v a . u t i l . A r r a y L i s t ; i m p o r tj a v a . u t i l . H a s h M a p ; i m p o r tj a v a . u t i l . L i s t ; i m p o r ta n d r o i d . a p p . A c t i v i t y ; i m p o r ta n d r o i d . o s . B u n d l e ; i m p o r ta n d r o i d . v i e w . V i e w ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n C h i l d C l i c k L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n G r o u p C l i c k L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n G r o u p C o l l a p s e L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n G r o u p E x p a n d L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . T o a s t ; p u b l i cc l a s sM a i n A c t i v i t ye x t e n d sA c t i v i t y{ E x p a n d a b l e L i s t A d a p t e rl i s t A d a p t e r ; E x p a n d a b l e L i s t V i e we x p L i s t V i e w ; L i s t < S t r i n g >l i s t D a t a H e a d e r ; H a s h M a p < S t r i n g ,L i s t < S t r i n g > >l i s t D a t a C h i l d ; @ O v e r r i d e p r o t e c t e dv o i do n C r e a t e ( B u n d l es a v e d I n s t a n c e S t a t e ){ s u p e r . o n C r e a t e ( s a v e d I n s t a n c e S t a t e ) ; s e t C o n t e n t V i e w ( R . l a y o u t . a c t i v i t y _ m a i n ) ; / /g e tt h el i s t v i e w e x p L i s t V i e w=( E x p a n d a b l e L i s t V i e w )f i n d V i e w B y I d ( R . i d . l v E x p ) ; / /p r e p a r i n gl i s td a t a p r e p a r e L i s t D a t a ( ) ;

l i s t A d a p t e r=n e wE x p a n d a b l e L i s t A d a p t e r ( t h i s ,l i s t D a t a H e a d e r ,l i s t D a t a C h i l d ) ; / /s e t t i n gl i s ta d a p t e r e x p L i s t V i e w . s e t A d a p t e r ( l i s t A d a p t e r ) ;

/ * *P r e p a r i n gt h el i s td a t a * / p r i v a t ev o i dp r e p a r e L i s t D a t a ( ){ l i s t D a t a H e a d e r=n e wA r r a y L i s t < S t r i n g > ( ) ; l i s t D a t a C h i l d=n e wH a s h M a p < S t r i n g ,L i s t < S t r i n g > > ( ) ; / /A d d i n gc h i l dd a t a l i s t D a t a H e a d e r . a d d ( " T o p2 5 0 " ) ; l i s t D a t a H e a d e r . a d d ( " N o wS h o w i n g " ) ; l i s t D a t a H e a d e r . a d d ( " C o m i n gS o o n . . " ) ; / /A d d i n gc h i l dd a t a L i s t < S t r i n g >t o p 2 5 0=n e wA r r a y L i s t < S t r i n g > ( ) ; t o p 2 5 0 . a d d ( " T h eS h a w s h a n kR e d e m p t i o n " ) ;

t o p 2 5 0 . a d d ( " T h eG o d f a t h e r " ) ; t o p 2 5 0 . a d d ( " T h eG o d f a t h e r :P a r tI I " ) ; t o p 2 5 0 . a d d ( " P u l pF i c t i o n " ) ; t o p 2 5 0 . a d d ( " T h eG o o d ,t h eB a da n dt h eU g l y " ) ; t o p 2 5 0 . a d d ( " T h eD a r kK n i g h t " ) ; t o p 2 5 0 . a d d ( " 1 2A n g r yM e n " ) ; L i s t < S t r i n g >n o w S h o w i n g=n e wA r r a y L i s t < S t r i n g > ( ) ; n o w S h o w i n g . a d d ( " T h eC o n j u r i n g " ) ; n o w S h o w i n g . a d d ( " D e s p i c a b l eM e2 " ) ; n o w S h o w i n g . a d d ( " T u r b o " ) ; n o w S h o w i n g . a d d ( " G r o w nU p s2 " ) ; n o w S h o w i n g . a d d ( " R e d2 " ) ; n o w S h o w i n g . a d d ( " T h eW o l v e r i n e " ) ; L i s t < S t r i n g >c o m i n g S o o n=n e wA r r a y L i s t < S t r i n g > ( ) ; c o m i n g S o o n . a d d ( " 2G u n s " ) ; c o m i n g S o o n . a d d ( " T h eS m u r f s2 " ) ; c o m i n g S o o n . a d d ( " T h eS p e c t a c u l a rN o w " ) ; c o m i n g S o o n . a d d ( " T h eC a n y o n s " ) ; c o m i n g S o o n . a d d ( " E u r o p aR e p o r t " ) ; l i s t D a t a C h i l d . p u t ( l i s t D a t a H e a d e r . g e t ( 0 ) ,t o p 2 5 0 ) ;/ /H e a d e r ,C h i l dd a t a l i s t D a t a C h i l d . p u t ( l i s t D a t a H e a d e r . g e t ( 1 ) ,n o w S h o w i n g ) ; l i s t D a t a C h i l d . p u t ( l i s t D a t a H e a d e r . g e t ( 2 ) ,c o m i n g S o o n ) ;

Run your project, you should see following output. (Note: The list view group indicators might change depending upon your android version)

DOWNLOAD

ERRORS

Search ..

ListView child item click listener


Detecting the child item click can be done by implementing setOnChildClickListener listener on listview.

/ /L i s t v i e wo nc h i l dc l i c kl i s t e n e r e x p L i s t V i e w . s e t O n C h i l d C l i c k L i s t e n e r ( n e wO n C h i l d C l i c k L i s t e n e r ( ){ @ O v e r r i d e p u b l i cb o o l e a no n C h i l d C l i c k ( E x p a n d a b l e L i s t V i e wp a r e n t ,V i e wv , i n tg r o u p P o s i t i o n ,i n tc h i l d P o s i t i o n ,l o n gi d ){ T o a s t . m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ) , l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) +":" +l i s t D a t a C h i l d . g e t ( l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) ) . g e t ( c h i l d P o s i t i o n ) ,T o a s t . L E N G T H _ S H O R T ) . s h o w ( ) ; r e t u r nf a l s e ; }

} ) ;

Listening when group is expanded


You may want to execute some lines of code when the listview group is expanded. For this you can use setOnGroupExpandListener which triggers an event when listview group expanded.

/ /L i s t v i e wG r o u pe x p a n d e dl i s t e n e r e x p L i s t V i e w . s e t O n G r o u p E x p a n d L i s t e n e r ( n e wO n G r o u p E x p a n d L i s t e n e r ( ){ @ O v e r r i d e p u b l i cv o i do n G r o u p E x p a n d ( i n tg r o u p P o s i t i o n ){ T o a s t . m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ) , l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n )+"E x p a n d e d " , T o a s t . L E N G T H _ S H O R T ) . s h o w ( ) ; }

} ) ;

Listening when group is collapsed


Implementing setOnGroupCollapseListener will trigger an event when listview group is collapsed.

/ /L i s t v i e wG r o u pc o l l a s p e dl i s t e n e r e x p L i s t V i e w . s e t O n G r o u p C o l l a p s e L i s t e n e r ( n e wO n G r o u p C o l l a p s e L i s t e n e r ( ){ @ O v e r r i d e p u b l i cv o i do n G r o u p C o l l a p s e ( i n tg r o u p P o s i t i o n ){ T o a s t . m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ) , l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n )+"C o l l a p s e d " , T o a s t . L E N G T H _ S H O R T ) . s h o w ( ) ; } ) ; }

Complete Code
Here is the final code for MainActivity.java

M a i n A c t i v i t y . j a v a
p a c k a g ei n f o . a n d r o i d h i v e . e x p a n d a b l e l i s t v i e w ; i m p o r tj a v a . u t i l . A r r a y L i s t ; i m p o r tj a v a . u t i l . H a s h M a p ; i m p o r tj a v a . u t i l . L i s t ; i m p o r ta n d r o i d . a p p . A c t i v i t y ; i m p o r ta n d r o i d . o s . B u n d l e ; i m p o r ta n d r o i d . v i e w . V i e w ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n C h i l d C l i c k L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n G r o u p C l i c k L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n G r o u p C o l l a p s e L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . E x p a n d a b l e L i s t V i e w . O n G r o u p E x p a n d L i s t e n e r ; i m p o r ta n d r o i d . w i d g e t . T o a s t ; p u b l i cc l a s sM a i n A c t i v i t ye x t e n d sA c t i v i t y{ E x p a n d a b l e L i s t A d a p t e rl i s t A d a p t e r ; E x p a n d a b l e L i s t V i e we x p L i s t V i e w ; L i s t < S t r i n g >l i s t D a t a H e a d e r ; H a s h M a p < S t r i n g ,L i s t < S t r i n g > >l i s t D a t a C h i l d ; @ O v e r r i d e p r o t e c t e dv o i do n C r e a t e ( B u n d l es a v e d I n s t a n c e S t a t e ){ s u p e r . o n C r e a t e ( s a v e d I n s t a n c e S t a t e ) ;

s e t C o n t e n t V i e w ( R . l a y o u t . a c t i v i t y _ m a i n ) ; / /g e tt h el i s t v i e w e x p L i s t V i e w=( E x p a n d a b l e L i s t V i e w )f i n d V i e w B y I d ( R . i d . l v E x p ) ; / /p r e p a r i n gl i s td a t a p r e p a r e L i s t D a t a ( ) ;

l i s t A d a p t e r=n e wE x p a n d a b l e L i s t A d a p t e r ( t h i s ,l i s t D a t a H e a d e r ,l i s t D a t a C h i l d ) ; / /s e t t i n gl i s ta d a p t e r e x p L i s t V i e w . s e t A d a p t e r ( l i s t A d a p t e r ) ; / /L i s t v i e wG r o u pc l i c kl i s t e n e r e x p L i s t V i e w . s e t O n G r o u p C l i c k L i s t e n e r ( n e wO n G r o u p C l i c k L i s t e n e r ( ){ @ O v e r r i d e p u b l i cb o o l e a no n G r o u p C l i c k ( E x p a n d a b l e L i s t V i e wp a r e n t ,V i e wv , i n tg r o u p P o s i t i o n ,l o n gi d ){ / /T o a s t . m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ) , / /" G r o u pC l i c k e d"+l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) , / /T o a s t . L E N G T H _ S H O R T ) . s h o w ( ) ; r e t u r nf a l s e ; }

} ) ;

/ /L i s t v i e wG r o u pe x p a n d e dl i s t e n e r e x p L i s t V i e w . s e t O n G r o u p E x p a n d L i s t e n e r ( n e wO n G r o u p E x p a n d L i s t e n e r ( ){ @ O v e r r i d e p u b l i cv o i do n G r o u p E x p a n d ( i n tg r o u p P o s i t i o n ){ T o a s t . m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ) , l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n )+"E x p a n d e d " , T o a s t . L E N G T H _ S H O R T ) . s h o w ( ) ; }

} ) ;

/ /L i s t v i e wG r o u pc o l l a s p e dl i s t e n e r e x p L i s t V i e w . s e t O n G r o u p C o l l a p s e L i s t e n e r ( n e wO n G r o u p C o l l a p s e L i s t e n e r ( ){ @ O v e r r i d e p u b l i cv o i do n G r o u p C o l l a p s e ( i n tg r o u p P o s i t i o n ){ T o a s t . m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ) , l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n )+"C o l l a p s e d " , T o a s t . L E N G T H _ S H O R T ) . s h o w ( ) ; } ) ; }

/ /L i s t v i e wo nc h i l dc l i c kl i s t e n e r e x p L i s t V i e w . s e t O n C h i l d C l i c k L i s t e n e r ( n e wO n C h i l d C l i c k L i s t e n e r ( ){ @ O v e r r i d e p u b l i cb o o l e a no n C h i l d C l i c k ( E x p a n d a b l e L i s t V i e wp a r e n t ,V i e wv , i n tg r o u p P o s i t i o n ,i n tc h i l d P o s i t i o n ,l o n gi d ){ / /T O D OA u t o g e n e r a t e dm e t h o ds t u b T o a s t . m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ) , l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) +":"

} ) ;

+l i s t D a t a C h i l d . g e t ( l i s t D a t a H e a d e r . g e t ( g r o u p P o s i t i o n ) ) . g e t ( c h i l d P o s i t i o n ) ,T o a s t . L E N G T H _ S H O R T ) . s h o w ( ) ; r e t u r nf a l s e ;

/ * *P r e p a r i n gt h el i s td a t a * / p r i v a t ev o i dp r e p a r e L i s t D a t a ( ){ l i s t D a t a H e a d e r=n e wA r r a y L i s t < S t r i n g > ( ) ; l i s t D a t a C h i l d=n e wH a s h M a p < S t r i n g ,L i s t < S t r i n g > > ( ) ; / /A d d i n gc h i l dd a t a l i s t D a t a H e a d e r . a d d ( " T o p2 5 0 " ) ; l i s t D a t a H e a d e r . a d d ( " N o wS h o w i n g " ) ; l i s t D a t a H e a d e r . a d d ( " C o m i n gS o o n . . " ) ; / /A d d i n gc h i l dd a t a L i s t < S t r i n g >t o p 2 5 0=n e wA r r a y L i s t < S t r i n g > ( ) ; t o p 2 5 0 . a d d ( " T h eS h a w s h a n kR e d e m p t i o n " ) ; t o p 2 5 0 . a d d ( " T h eG o d f a t h e r " ) ; t o p 2 5 0 . a d d ( " T h eG o d f a t h e r :P a r tI I " ) ; t o p 2 5 0 . a d d ( " P u l pF i c t i o n " ) ; t o p 2 5 0 . a d d ( " T h eG o o d ,t h eB a da n dt h eU g l y " ) ; t o p 2 5 0 . a d d ( " T h eD a r kK n i g h t " ) ; t o p 2 5 0 . a d d ( " 1 2A n g r yM e n " ) ; L i s t < S t r i n g >n o w S h o w i n g=n e wA r r a y L i s t < S t r i n g > ( ) ; n o w S h o w i n g . a d d ( " T h eC o n j u r i n g " ) ; n o w S h o w i n g . a d d ( " D e s p i c a b l eM e2 " ) ; n o w S h o w i n g . a d d ( " T u r b o " ) ; n o w S h o w i n g . a d d ( " G r o w nU p s2 " ) ; n o w S h o w i n g . a d d ( " R e d2 " ) ; n o w S h o w i n g . a d d ( " T h eW o l v e r i n e " ) ; L i s t < S t r i n g >c o m i n g S o o n=n e wA r r a y L i s t < S t r i n g > ( ) ; c o m i n g S o o n . a d d ( " 2G u n s " ) ; c o m i n g S o o n . a d d ( " T h eS m u r f s2 " ) ; c o m i n g S o o n . a d d ( " T h eS p e c t a c u l a rN o w " ) ; c o m i n g S o o n . a d d ( " T h eC a n y o n s " ) ; c o m i n g S o o n . a d d ( " E u r o p aR e p o r t " ) ; l i s t D a t a C h i l d . p u t ( l i s t D a t a H e a d e r . g e t ( 0 ) ,t o p 2 5 0 ) ;/ /H e a d e r ,C h i l dd a t a l i s t D a t a C h i l d . p u t ( l i s t D a t a H e a d e r . g e t ( 1 ) ,n o w S h o w i n g ) ; l i s t D a t a C h i l d . p u t ( l i s t D a t a H e a d e r . g e t ( 2 ) ,c o m i n g S o o n ) ;

Share this article on

238
Like

7
Tw eet

Report a Bug in this article


(If you find any error either in code or content please help me in improvising the content)

Email address / Full name

Give brief description about the bug...

Report

Follow @RaviTam ada

1,754 follow ers

Like

10k

Tw eet

360

871

Subscribe for latest updates

101596
SUBSCRIBE

Enter your email here

AndroidHive
Like 10,383 people like AndroidHive.

Facebook social plugin

Tag Cloud
Animat ion Dashboard Gest ures json Pinch SQLit e Video Apps Asy nc Beginner GCM I nt ermediat e PH P Camera

Dat abase Google GPS Maps

facebook Grid My SQL

List View Quick Tips Swipe xml

sessions Tab View

Spinner Twit t er UI

MOST POPULAR

NETWORK

Android

SQLite

Database

Tutorial - 507,734 views

design.androidhive.info

DESIGN TIPS

Android Custom ListView with Image and Text - 418,983 views

Android JSON Parsing Tutorial 393,232 views

tips.androidhive.info

How to connect Android with PHP, MySQL - 357,808 views

errors.androidhive.info

ERRORS

Android (GCM),

Push PHP

Notifications MySQL -

using Google Cloud Messaging and 285,445 views

download.androidhive.info

DOWNLOAD

Android Tab Layout Tutorial 283,711 views

Android Login and Registration with PHP, MySQL and SQLite 276,103 views

101596791154
&

subscribers

downloads

Android XML Parsing Tutorial 223,876 views

REQUEST TUTORIAL
Email / Name * Your email id or name

Android Login and Registration Screen Design - 207,971 views

10 Android

ListView

Tutorial

194,449 views

Description *

Brief description about your thought. (Please don't spam)

SEND
Creative Commons Attribution 3.0 Unported License

.
2013 AndroidHive | All Rights Reserved Advertise | Privacy Policy | Terms & Conditions

You might also like