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