English | Site Directory

Android - An Open Handset Alliance Project

android.widget
public class

android.widget.TwoLineListItem

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.view.ViewGroup ViewManager ViewParent
android.widget.RelativeLayout
android.widget.TwoLineListItem

A view group with two children, intended for use in ListViews. This item has two TextViews elements (or subclasses) with the ID values text1 and text2. There is an optional third View element with the ID selectedIcon, which can be any View subclass (though it is typically a graphic View, such as ImageView) that can be displayed when a TwoLineListItem has focus. Android supplies a standard layout resource for TwoLineListView (which does not include a selected item icon), but you can design your own custom XML layout for this object as shown here:

<?xml version="1.0" encoding="utf-8"?>
<!--
/*
 * Copyright (C) 2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ImageView android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/sym_presence_offline"/>

    <TextView android:id="@android:id/text1"
        android:layout_marginTop="1dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRight="@id/icon"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView android:id="@android:id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/text1"
        android:layout_alignLeft="@android:id/text1"
        android:paddingBottom="4dip"
        android:includeFontPadding="false"
        android:textSize="15sp"
        android:textStyle="normal" />

    <ImageView android:id="@android:id/selectedIcon"
        android:layout_marginTop="9dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="7dip"
        android:src="@android:drawable/sym_action_call"/>
</TwoLineListItem>

Also see ViewGroup.LayoutParams for layout attributes.

Summary

XML Attributes

Attribute name Related methods  
android:mode    
XML Attributes inherited from class android.view.ViewGroup
XML Attributes inherited from class android.view.View

Constants

      Value  
int  MODE_COLLAPSING  When selected show two lines, when not shot one line   0x00000002 
int  MODE_ONE_LINE  Only ever show the first line   0x00000001 
int  MODE_TWO_LINE  Always show two lines   0x00000003 
Constants inherited from class android.widget.RelativeLayout
Constants inherited from class android.view.ViewGroup
Constants inherited from class android.view.View
Fields inherited from class android.view.ViewGroup
Fields inherited from class android.view.View

Public Constructors

          TwoLineListItem(Context context)
          TwoLineListItem(Context context, AttributeSet attrs, Map inflateParams)
          TwoLineListItem(Context context, AttributeSet attrs, Map inflateParams, int defStyle)

Public Methods

        void  disableSelectedIcon()
Hides the "item selected" icon (if the layout defines one).
        void  enableSelectedIcon()
Displays the "item selected" icon (if the layout defines one).
        int  getMode()
Returns the current display mode (see the constants defined by this class).
        TextView  getText1()
Returns a handle to the item with ID text1.
        TextView  getText2()
Returns a handle to the item with ID text2.
        void  setMode(int mode)
Sets the display mode.
        void  setSelected(boolean selected)
Changes the selection state of this view.

Protected Methods

        void  onFinishInflate()
Finalize inflating a view from XML.
Methods inherited from class android.widget.RelativeLayout
Methods inherited from class android.view.ViewGroup