1 /* 2 * Copyright (C) 2008 Esmertec AG. 3 * Copyright (C) 2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mms.ui; 19 20 import android.content.Context; 21 import android.view.LayoutInflater; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.widget.ArrayAdapter; 25 import android.widget.ImageView; 26 import android.widget.TextView; 27 28 import java.util.List; 29 30 import com.android.mms.R; 31 32 /** 33 * An adapter to store icons. 34 */ 35 public class IconListAdapter extends ArrayAdapter<IconListAdapter.IconListItem> { 36 protected LayoutInflater mInflater; 37 private static final int mResource = R.layout.icon_list_item; 38 39 public IconListAdapter(Context context, 40 List<IconListItem> items) { 41 super(context, mResource, items); 42 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 43 } 44 45 @Override 46 public View getView(int position, View convertView, ViewGroup parent) { 47 TextView text; 48 ImageView image; 49 50 View view; 51 if (convertView == null) { 52 view = mInflater.inflate(mResource, parent, false); 53 } else { 54 view = convertView; 55 } 56 57 // Set text field 58 text = (TextView) view.findViewById(R.id.text1); 59 text.setText(getItem(position).getTitle()); 60 61 // Set resource icon 62 image = (ImageView) view.findViewById(R.id.icon); 63 image.setImageResource(getItem(position).getResource()); 64 65 return view; 66 } 67 68 public static class IconListItem { 69 private final String mTitle; 70 private final int mResource; 71 72 public IconListItem(String title, int resource) { 73 mResource = resource; 74 mTitle = title; 75 } 76 77 public String getTitle() { 78 return mTitle; 79 } 80 81 public int getResource() { 82 return mResource; 83 } 84 } 85 } 86