【API翻译】ExpandableListActivity

An activity that displays an expandable list of items by binding to a data source implementing the ExpandableListAdapter, and exposes event handlers when the user selects an item.

一个通过绑定到实现了ExpandableListAdapter的数据源来显示扩展列表项的activity,当用户选择了一个选项的时候显露事件处理器(event handlers)。


ExpandableListActivity hosts a ExpandableListView object that can be bound to different data sources that provide a two-levels of data (the top-level is group, and below each group are children). Binding, screen layout, and row layout are discussed in the following sections.

ExpandableListActivity 寄存于 一个ExpandableListActivity 对象时   能够跳到不同数据源,就是这能提供两级数据(顶级是父组,每个父组之下的是子组)的绑定.

屏幕布局,还有行布局将在下面的章节中描述。


Screen Layout

屏幕布局


ExpandableListActivity has a default layout that consists of a single, full-screen, centered expandable list. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain an ExpandableListView object with the id "@android:id/list" (orlistif it's in code)

ExpandableListActivity  具有 一个默认布局 ,它包含:一个单一的、全屏的、居中的expandable list。不管怎样,如果你想要的话,你可以自定义屏幕布局, 通过在onCreate()方法中 的setContentView() 来.设置你自己的视图布局 ,


Optionally, your custom view can contain another view object of any type to display when the list view is empty. This "empty list" notifier must have an id "android:empty". Note that when an empty view is present, the expandable list view will be hidden when there is no data to display.

而且,当列表视图为空的时候,你自定义的视图可以显示包含其他任意类型的视图对象。提示“空列表”的提示器它的id一定要为“android:empty”。注意!当现在存在一个空视图、没有数据能显示的时候,这个expandablelist视图将会被隐藏 。


The following code demonstrates an (ugly) custom screen layout. It has a list with a green background, and an alternate red "no data" message. 

下列代码示范是一个 (简陋的)自定义屏幕布局。它包含一个绿色背景的list,还有一个的红色“no data”的候补信息

<?xml version="1.0" encoding="UTF-8"?>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingLeft="8dp"
        android:paddingRight="8dp" >

        <ExpandableListView
            android:id="@id/android:list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#00FF00"
            android:drawSelectorOnTop="false" />

        <TextView
            android:id="@id/android:empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FF0000"
            android:text="No data" />
    </LinearLayout>

Row Layout

行布局


The ExpandableListAdapter set in the ExpandableListActivity via setListAdapter(ExpandableListAdapter) provides the Views for each row. This adapter has separate methods for providing the group Views and child Views. There are a couple provided ExpandableListAdapters that simplify use of adapters: SimpleCursorTreeAdapter and SimpleExpandableListAdapter.

这个ExpandableListAdapter在 ExpandableListActivity里设置, 后者 通过setListAdapter(ExpandableListAdapter) 来给每行提供视图。这个adapter有一个分离方法提供给父组视图和子组视图。 这里是提供一堆 adapters:SimpleCursorTreeAdapter 和SimpleExpandableListAdapter,用来简化使用ExpandableListAdapters。
 

With these, you can specify the layout of individual rows for groups and children in the list. These constructor takes a few parameters that specify layout resources for groups and children. It also has additional parameters that let you specify which data field to associate with which object in the row layout resource. The SimpleCursorTreeAdapter fetches data fromCursors and the SimpleExpandableListAdapter fetches data fromLists of Maps.

有了这些,你就可以在行布局中指定列表里的的特定父组和特定子组。这个构造器需要一些参数才能指定父组和子组的布局资源。它还有一些额外的参数来让你指出哪些数据匹配行布局资源中哪个对象。SimpleCursorTreeAdapter 接收来自游标的数据 ,SimpleExpandableListAdapter  接收来自Lists和Maps的数据


Android provides some standard row layout resources. These are in the R.layout class, and have names such as simple_list_item_1, simple_list_item_2, and two_line_list_item. The following layout XML is the source for the resource two_line_list_item, which displays two data fields,one above the other, for each list row. 

安卓提供了一些标准行布局资源。这些资源放在 R.layout 类中,且其名字类似simple_list_item_1, simple_list_item_2,还有 two_line_list_item。下列xml布局文件 是资源two_line_list_item的来源,这个布局显示两个文本域,一个在另一个之上,遍及list的每一行。


<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp" />
    </LinearLayout>


You must identify the data bound to each TextView object in this layout. The syntax for this is discussed in the next section.

你一定要确定每个在布局中的定义的TextView对象都是唯一的,这种语法在下一个部分描述。


Binding to Data

绑定数据


You bind the ExpandableListActivity's ExpandableListView object to data using a class that implements theExpandableListAdapter interface. Android provides two standard list adapters:SimpleExpandableListAdapter for static data (Maps), andSimpleCursorTreeAdapter for Cursor query results.

你使用一个类给ExpandableListActivity's 的ExpandableListView 对象绑定数据 , 这样来实现ExpandableListAdapter 接口 。安卓提供两个标准list adapters:SimpleExpandableListAdapter 对应 静态数据 (Maps),  SimpleCursorTreeAdapter 对应游标查询结果.



..........

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值