• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
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 android.widget.cts;
18 
19 import android.os.Bundle;
20 import android.widget.Button;
21 import android.widget.ExpandableListView;
22 import android.widget.cts.util.ExpandableListScenario;
23 
24 public class ExpandableListWithHeaders extends ExpandableListScenario {
25     private static final int[] sNumChildren = {1, 4, 3, 2, 6};
26     private static final int sNumOfHeadersAndFooters = 12;
27 
28     @Override
init(ExpandableParams params)29     protected void init(ExpandableParams params) {
30         params.setStackFromBottom(false)
31                 .setStartingSelectionPosition(-1)
32                 .setNumChildren(sNumChildren)
33                 .setItemScreenSizeFactor(0.14)
34                 .setConnectAdapter(false);
35     }
36 
37     @Override
onCreate(Bundle icicle)38     protected void onCreate(Bundle icicle) {
39         super.onCreate(icicle);
40 
41         final ExpandableListView expandableListView = getExpandableListView();
42         expandableListView.setItemsCanFocus(true);
43 
44         for (int i = 0; i < sNumOfHeadersAndFooters; i++) {
45             Button header = new Button(this);
46             header.setText("Header View");
47             expandableListView.addHeaderView(header);
48         }
49 
50         for (int i = 0; i < sNumOfHeadersAndFooters; i++) {
51             Button footer = new Button(this);
52             footer.setText("Footer View");
53             expandableListView.addFooterView(footer);
54         }
55 
56         // Set adapter here AFTER we set header and footer views
57         setAdapter(expandableListView);
58     }
59 
60     /**
61      * @return The number of headers (and the same number of footers)
62      */
getNumOfHeadersAndFooters()63     public int getNumOfHeadersAndFooters() {
64         return sNumOfHeadersAndFooters;
65     }
66 }
67