TwoLineListItem.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/* 2 * Copyright (C) 2006 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 17package android.widget; 18 19import com.android.internal.R; 20 21 22import android.annotation.Widget; 23import android.content.Context; 24import android.content.res.TypedArray; 25import android.util.AttributeSet; 26import android.view.View; 27import android.widget.RelativeLayout; 28 29/** 30 * <p>A view group with two children, intended for use in ListViews. This item has two 31 * {@link android.widget.TextView TextViews} elements (or subclasses) with the ID values 32 * {@link android.R.id#text1 text1} 33 * and {@link android.R.id#text2 text2}. There is an optional third View element with the 34 * ID {@link android.R.id#selectedIcon selectedIcon}, which can be any View subclass 35 * (though it is typically a graphic View, such as {@link android.widget.ImageView ImageView}) 36 * that can be displayed when a TwoLineListItem has focus. Android supplies a 37 * {@link android.R.layout#two_line_list_item standard layout resource for TwoLineListView} 38 * (which does not include a selected item icon), but you can design your own custom XML 39 * layout for this object as shown here:</p> 40 * {@sample packages/apps/Phone/res/layout/dialer_list_item.xml} 41 * 42 * @attr ref android.R.styleable#TwoLineListItem_mode 43 */ 44@Widget 45public class TwoLineListItem extends RelativeLayout { 46 47 private TextView mText1; 48 private TextView mText2; 49 50 public TwoLineListItem(Context context) { 51 this(context, null, 0); 52 } 53 54 public TwoLineListItem(Context context, AttributeSet attrs) { 55 this(context, attrs, 0); 56 } 57 58 public TwoLineListItem(Context context, AttributeSet attrs, int defStyle) { 59 super(context, attrs, defStyle); 60 61 TypedArray a = context.obtainStyledAttributes(attrs, 62 com.android.internal.R.styleable.TwoLineListItem, defStyle, 0); 63 64 a.recycle(); 65 } 66 67 @Override 68 protected void onFinishInflate() { 69 super.onFinishInflate(); 70 71 mText1 = (TextView) findViewById(com.android.internal.R.id.text1); 72 mText2 = (TextView) findViewById(com.android.internal.R.id.text2); 73 } 74 75 /** 76 * Returns a handle to the item with ID text1. 77 * @return A handle to the item with ID text1. 78 */ 79 public TextView getText1() { 80 return mText1; 81 } 82 83 /** 84 * Returns a handle to the item with ID text2. 85 * @return A handle to the item with ID text2. 86 */ 87 public TextView getText2() { 88 return mText2; 89 } 90} 91