Home | History | Annotate | Download | only in listview
      1 /*
      2  * Copyright (C) 2007 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.listview;
     18 
     19 import android.view.View;
     20 import android.view.ViewGroup;
     21 
     22 import android.util.ListItemFactory;
     23 import android.util.ListScenario;
     24 
     25 /**
     26  * List that has different view types
     27  */
     28 public class ListHeterogeneous extends ListScenario {
     29 
     30     @Override
     31     protected void init(Params params) {
     32         params.setNumItems(50)
     33                 .setItemScreenSizeFactor(1.0 / 8)
     34                 .setItemsFocusable(true)
     35                 .setHeaderViewCount(3)
     36                 .setFooterViewCount(2);
     37     }
     38 
     39     @Override
     40     protected View createView(int position, ViewGroup parent, int desiredHeight) {
     41         switch (position % 3) {
     42         case 0:
     43             return ListItemFactory.text(
     44                     position, parent.getContext(), getValueAtPosition(position), desiredHeight);
     45         case 1:
     46             return ListItemFactory.button(
     47                     position, parent.getContext(), getValueAtPosition(position), desiredHeight);
     48         case 2:
     49             return ListItemFactory.doubleText(
     50                     position, parent.getContext(), getValueAtPosition(position), desiredHeight);
     51         }
     52 
     53         return null;
     54     }
     55 
     56     @Override
     57     public View convertView(int position, View convertView, ViewGroup parent) {
     58         switch (position % 3) {
     59         case 0:
     60             return ListItemFactory.convertText(convertView, getValueAtPosition(position), position);
     61         case 1:
     62             return ListItemFactory.convertButton(convertView, getValueAtPosition(position),
     63                     position);
     64         case 2:
     65             return ListItemFactory.convertDoubleText(convertView, getValueAtPosition(position),
     66                     position);
     67         }
     68 
     69         return null;
     70     }
     71 
     72     @Override
     73     public int getItemViewType(int position) {
     74         return position % 3;
     75     }
     76 
     77     @Override
     78     public int getViewTypeCount() {
     79         return 3;
     80     }
     81 
     82 
     83 }
     84