layouts

又翻译好了一篇,继续加油

Layouts

In this document

1.Write the XML

2.Load the XML Resource

3.Attributes

1.ID

2.Layout Parameters

4.Layout Position

5.Size, Padding and Margins

6.Common Layouts

7.Building Layouts with an Adapter

1.Filling an adapter view with data

2.Handling click events

Key classes

1.View

2.ViewGroup

3.ViewGroup.LayoutParams

See also

1.Building a Simple User Interface

A layout defines the visual structure for a user interface, such as the UI for an activity or app widget. You can declare a layout in two ways:

· Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts.

· Instantiate layout elements at runtime. Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

布局定义为用户接口可视结构,就像为活动和app组件的UI。你能申明布局在下面两种方法:

在xml申明UI元素。android工程提供易懂xml词汇。关联视图类和子类,就像这些给组件和布局。

在运行时间举例布局。应用程序化地能创建视图或视图组对象(控制属性)

The Android framework gives you the flexibility to use either or both of these methods for declaring and managing your application's UI. For example, you could declare your application's default layouts in XML, including the screen elements that will appear in them and their properties. You could then add code in your application that would modify the state of the screen objects, including those declared in XML, at run time.

android基础结构让你适应使用两种或其中一种来申明和管理应用UI。在xml,你能定义应用默认布局,包括屏幕元素,在屏幕中呈现的元素,以及他们属性。你能在应用程序增加代码,在运行时间修改屏幕对象的状态,包括在xml中定义的对象。

· The ADT Plugin for Eclipse offers a layout preview of your XML — with the XML file opened, select the Layouttab.

· You should also try the Hierarchy Viewer tool, for debugging layouts —it reveals layout property values, draws wireframes with padding/margin indicators, and full rendered views while you debug on the emulator or device.

· The layoutopttool lets you quickly analyze your layouts and hierarchies for inefficiencies or other problems.

ADT Plugin for Eclipse提供xml布局预览-xml文件打开时,选择布局版。

你能够尝试等级视图工具,调试布局--展示了属性值,绘制线框图与填充/边距指示符,并充分呈现的视图,当你在模拟器或设备上进行调试。

布局工具让你快速分析布局和层次结构解决效率低下或其他问题。

The advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior. Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile. For example, you can create XML layouts for different screen orientations, different device screen sizes, and different languages. Additionally, declaring the layout in XML makes it easier to visualize the structure of your UI, so it's easier to debug problems. As such, this document focuses on teaching you how to declare your layout in XML. If you're interested in instantiating View objects at runtime, refer to the ViewGroup and Viewclass references.

声明在 XML 中的 UI 的优点是它允许你从控制其行为的代码中更好地分离应用程序的演示。您的用户界面描述是外部的应用程序代码,这意味着您可以修改或适应它而无需修改您的应用程序源代码和重新编译。例如,您可以创建 XML 布局为不同的屏幕方向、 不同设备的屏幕大小,和不同的语言。此外,在 XML 声明布局使你的 UI 的结构容易可视化,所以它更容易调试的问题。为此,这文档关注叫你如何声明布局在xml。如果你感兴趣在运行时举例视图对象,参阅视图组或视图类参考。

In general, the XML vocabulary for declaring UI elements closely follows the structure and naming of the classes and methods, where element names correspond to class names and attribute names correspond to methods. In fact, the correspondence is often so direct that you can guess what XML attribute corresponds to a class method, or guess what class corresponds to a given xml element. However, note that not all vocabulary is identical. In some cases, there are slight naming differences. For example, the EditText element has a text attribute that corresponds to EditText.setText().

一般情况下,XML 词汇表的声明 UI 元素是密切跟随如下的结构和命名的类和方法,在对应的类名的元素名称和对应的方法的属性名称。事实上,经常是如此直接的对应关系,所以你可以猜猜什么 XML 属性对应于一个类的方法,或猜什么类对应于一个给定的 xml 元素。但是,注意并不是所有的词汇是完全相同。在某些情况下,有轻微命名的差异。例如,EditText 元素有text属性,对应 EditText .setText()。

Tip: Learn more about different layout types in Common Layout Objects. There are also a collection of tutorials(教程) on building various layouts in theHello Views tutorial guide.

Write the XML

Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML —with a series of nested elements.

很多方法创建web 页在html,有各种各样的内置元素.

Each layout file must contain exactly one root element, which must be a View or ViewGroup object. Once you've defined the root element, you can add additional layout objects or widgets as child elements to gradually build a View hierarchy that defines your layout. For example, here's an XML layout that uses a vertical LinearLayoutto hold a TextView and a Button:

每个布局文件必须包含一个根元素,必须是一个视图或分组的对象。一旦您已经定义的根元素,您可以作为子元素,逐步构建视图层次结构定义您的布局中添加其他布局对象或窗口小部件。比如,有一个xml布局使用了LinearLayout控制TextView and a Button

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

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

<TextView android:id="@+id/text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello, I am a TextView"/>

<Buttonandroid:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello, I am a Button"/>

</LinearLayout>

After you've declared your layout in XML, save the file with the .xml extension, in your Android project's res/layout/directory, so it will properly compile.

你已经声明在 XML 布局后,保存的文件。xml 扩展名,请在您的 Android 项目 res/布局/目录下,因此它将正确编译。

More information about the syntax for a layout XML file is available in the Layout Resourcesdocument.

Load the XML Resource

When you compile your application, each XML layout file is compiled into aView resource. You should load the layout resource from your application code, in your Activity.onCreate() callback implementation. Do so by calling setContentView(), passing it the reference to your layout resource in the form of: R.layout.layout_file_name For example, if your XML layout is saved as main_layout.xml, you would load it for your Activity like so:

当您编译您的应用程序时,每个 XML 布局文件被编译到视图资源。在您的活动中,在onCreate() 回调实现应用程序代码加载布局资源。通过调用 setContentView(),通过它对您的布局资源的引用的形式,这样做: R.layout.layout_file_name例如,如果您的 XML 布局保存为 main_layout 。xml 中,你将会加载它为你的活动就像这样:

publicvoid onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main_layout);

}

The onCreate() callback method in your Activity is called by the Android framework when your Activity is launched (see the discussion about lifecycles, in the Activitiesdocument).

在活动发起时,onCreate()回调方法在活动中被android基础活动调用。

Attributes

Every View and ViewGroup object supports their own variety of XML attributes. Some attributes are specific to a View object (for example, TextView supports the textSize attribute), but these attributes are also inherited by any View objects that may extend this class. Some are common to all View objects, because they are inherited from the root View class (like the id attribute). And, other attributes are considered "layout parameters," which are attributes that describe certain layout orientations of the View object, as defined by that object's parent ViewGroup object.

每个视图和视图分组对象支持他们自己的 XML 属性。有些属性是特定于某个视图对象 (例如,TextView 支持 textSize 属性),但这些属性也由可能扩展此类的任何视图对象继承。有些共同的所有视图对象,因为它们都继承自根视图类 (如 id属性)。其他的属性被视为"布局参数,"是描述某些布局方向的视图对象的属性,如由该对象的父视图分组对象定义的。

ID

Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute. This is an XML attribute common to all View objects (defined by the View class) and you will use it very often. The syntax for an ID, inside an XML tag is:

任何视图对象可能有整数 ID 来与之关联,唯一地标识树中的视图。当编译应用程序时,此 ID 引用作为一个整数,但 id属性,XML 文件中的分配的 ID 通常做为字符串。这是常见的 (由视图类定义) 的所有视图对象的 XML 属性,你将会经常使用它。XML 标记的内部ID语法:

android:id="@+id/my_button"

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file). There are a number of other ID resources that are offered by the Android framework. When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so:

在字符串的开头的符号 (@) 指示 XML 分析器应分析和展开的 ID 字符串的其余部分,并确认它作为 ID 资源。加上-符号 (+) 表示这就是一个新的资源名称,必须创建并添加到我们的资源 (在R.java 文件)。有许多其他 Android 框架所提供的 ID 资源。引用时 Android 资源 ID,您不需要加上+符号,但必须添加 android 软件包的命名空间,就像这样:

android:id="@android :id/empty"

With the android package namespace in place, we're now referencing an ID from the android.Rresources class, rather than the local resources class.

当放置 android 包命名空间中的地方,我们现在从 android.R资源类引用ID,而不是本地资源类。

In order to create views and reference them from the application, a common pattern is to:

为了创建的视图,然后从该应用程序引用它们,一个共同的模式是:

1.Define a view/widget in the layout file and assign it a unique ID:

<Button

android:id="@+id/my_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/my_button_text"/>

2.Then create an instance of the view object and capture it from the layout (typically in the onCreate()method):

创建视图对象实例,并且从布局捕获他们(典型在onCreate())

Button myButton =(Button) findViewById(R.id.my_button);

Defining IDs for view objects is important when creating a RelativeLayout. In a relative layout, sibling views can define their layout relative to another sibling view, which is referenced by the unique ID.

创建 RelativeLayout 时,视图对象定义 Id 很重要。在相对布局中,同级的视图可以定义它们的布局相对于另一个同级视图,另外视图是引用的唯一 id。

An ID need not be unique throughout the entire tree, but it should be unique within the part of the tree you are searching (which may often be the entire tree, so it's best to be completely unique when possible).

在整个树中ID 不需要唯一的,但它应该是唯一,在你正在搜索的部分树中 (这往往可能整个树,所以最好是可能时完全是唯一) 的一部分。

Layout Parameters

XML layout attributes named layout_somethingdefine layout parameters for the View that are appropriate for the ViewGroup in which it resides.

命名 为layout_something的XML 布局属性定义视图布局参数,视图适当的驻留在视图分组中。

Every ViewGroup class implements a nested class that extends ViewGroup.LayoutParams. This subclass contains property types that define the size and position for each child view, as appropriate for the view group. As you can see in figure 1, the parent view group defines layout parameters for each child view (including the child view group).

每个视图组类实现一个嵌套的类,这个类试扩展自ViewGroup.LayoutParams。这个子类包含 为子视图组定义以适用视图组大小和位置,属性类型。就像你可以在图 1 中看到,父视图组定义了每个 (包括子视图组) 的子视图的布局参数。

Figure 1.Visualization of a view hierarchy with layout parameters associated with each view.

与每个视图关联的布局参数的视图层次结构的可视化。

Note that every LayoutParams subclass has its own syntax for setting values. Each child element must define LayoutParams that are appropriate for its parent, though it may also define different LayoutParams for its own children.

请注意每个 LayoutParams 子类有它自己的语法设置值。每个子元素必须定义为适合于其父,虽然它也可以为它自己的孩子来定义不同的LayoutParams 。

All view groups include a width and height (layout_width andlayout_height), and each view is required to define them. Many LayoutParams also include optional margins and borders.

所有视图组都包括一个宽度和高度 (layout_width andlayout_height),并定义它们所需的每个视图。许多 LayoutParams 还包括可选的边距和边框。

You can specify width and height with exact measurements, though you probably won't want to do this often. More often, you will use one of these constants to set the width or height:

可以用精确的测量指定宽度和高度,虽然你可能不会想要经常这样做。更多时候,您将使用这些常量之一来设置的宽度或高度:

· wrap_content tells your view to size itself to the dimensions required by its content

· fill_parent (renamed match_parentin API Level 8) tells your view to become as big as its parent view group will allow.

wrap_content 告诉视图调整自身的尺寸大小符合由其内容所需的视图。

fill_parent (改名为 match_parent API 级别 8) 告诉您的视图,成为其父视图组将允许的那么大。

In general, specifying a layout width and height using absolute units such as pixels is not recommended. Instead, using relative measurements such as density-independent pixel units (dp), wrap_content, orfill_parent, is a better approach, because it helps ensure that your application will display properly across a variety of device screen sizes. The accepted measurement types are defined in theAvailable Resourcesdocument.

一般情况下,不建议指定布局的宽度和高度使用绝对单位如像素为单位)。相反,使用相对测量,如密度无关的像素单位 (dp),wrap_content,orfill_parent,是一个更好的方法,因为它有助于确保您的应用程序将正确显示,可以跨多种设备的屏幕大小。接受的测量类型定义中有效 Resourcesdocument 加密。

Layout Position

The geometry of a view is that of a rectangle. A view has a location, expressed as a pair of left and top coordinates, and two dimensions, expressed as a width and a height. The unit for location and dimensions is the pixel.

一个视图的几何形状是一个矩形。视图有一个位置,作为一对左侧和顶部的坐标表示和两个维度,表示为一个宽度和一个高度。位置和尺寸的单位是像素。

It is possible to retrieve the location of a view by invoking the methods getLeft() and getTop(). The former returns the left, or X, coordinate of the rectangle representing the view. The latter returns the top, or Y, coordinate of the rectangle representing the view. These methods both return the location of the view relative to its parent. For instance, when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of its direct parent.

它是可能通过调用的方法 getLeft() 和 getTop() 检索视图的位置。前者返回左或向 X,表示视图矩形的坐标。后者返回的顶部或 Y,表示视图矩形的坐标。这些方法返回相对于其父视图的位置。例如,getLeft() 返回时 20,这意味着该视图是位于 20 像素为单位) 到它的直接父级的左边缘的右侧。

In addition, several convenience methods are offered to avoid unnecessary computations, namely getRight() and getBottom(). These methods return the coordinates of the right and bottom edges of the rectangle representing the view. For instance, calling getRight() is similar to the following computation: getLeft() + getWidth().

此外,提供几种方便的方法,避免不必要的计算,即 getRight() 和 getBottom()。这些方法返回的矩形表示视图的右侧和底部边缘的坐标。例如,调用 getRight() 是类似于以下计算: getLeft() + getWidth()。

Size, Padding and Margins

The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.

视图的大小用宽度和高度表示的。一个视图实际上拥有两个成对的宽度值和高度值。

The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent. The measured dimensions can be obtained by calling getMeasuredWidth() and getMeasuredHeight().

第一对被称为测量宽度和测量高度。这些维度定义在其父级内想要多大。测量的尺寸可以通过调用 getMeasuredWidth() 和 getMeasuredHeight()得到。

The second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height. The width and height can be obtained by calling getWidth() and getHeight().

第二对被简单地称为宽度和高度,或有时称为绘制宽度与绘制高度。这些维度定义视图在屏幕上,在绘图的时间和布局后的实际大小。这些值可能会,但并没有一定使其不同于测量的宽度和高度。可以通过调用 getWidth() 和 getHeight() 获得的宽度和高度。

To measure its dimensions, a view takes into account its padding. The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific amount of pixels. For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge. Padding can be set using the setPadding(int, int, int, int) method and queried by calling getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom().

要测量其尺寸,视图会考虑其填充。为视图的左侧、 顶部、 右侧和底部部分以像素表示填充。可以使用填充来抵消视图的内容,通过指定很多像素)。例如,2 左的填充将推向视图的内容 2 个像素的左边缘的权利。填充可以设置使用 setPadding (int,int,int,int) 的方法,通过调用 getPaddingLeft()、 getPaddingTop()、 getPaddingRight()、 getPaddingBottom() 查询。

Even though a view can define a padding, it does not provide any support for margins. However, view groups provide such a support. Refer to ViewGroup and ViewGroup.MarginLayoutParamsfor further information.

即使一个视图可以定义填充,它不提供任何支持的边距。然而,视图组提供这种支持。请参阅视图分组和分组。MarginLayoutParamsfor 进一步的信息。

For more information about dimensions, see Dimension Values.

Common Layouts

Each subclass of the ViewGroupclass provides a unique way to display the views you nest within it. Below are some of the more common layout types that are built into the Android platform.

每个ViewGroup 类的子类提供唯一的方式来显示你嵌套在它的视图。以下是一些更常见的布局类型,都是内置在 Android 平台里。

Linear Layout

A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.

组织子对象为单独的水平或垂直行的布局。如果窗口长度超过屏幕长就会创建滚动条。

Relative Layout

Enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent).

是你能够确定彼此之前子对象位置(a在b的左边), 或者是父对象(和父的顶端对齐)

Web View

Displays web pages

Note:Although you can nest one or more layouts within another layout to acheive your UI design, you should strive to keep your layout hierarchy as shallow as possible. Your layout draws faster if it has fewer nested layouts (a wide view hierarchy is better than a deep view hierarchy).

虽然您可以嵌套在另一个布局,以实现您的 UI 设计内的一个或多个布局,你应该努力保持您的布局层次尽可能浅。您的布局更快地绘制如果它有更少的嵌套的布局 (宽视图层次结构是比深视图层次更好)。

Linear Layout

A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.

Relative Layout

Enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent).

Web View

Displays web pages.

Building Layouts with an Adapter

用代码绑定布局

When the content for your layout is dynamic or not pre-determined, you can use a layout that subclasses AdapterView to populate the layout with views at runtime. A subclass of the AdapterView class uses an Adapter to bind data to its layout. The Adapter behaves as a middle-man between the data source and the AdapterView layout—the Adapter retreives the data (from a source such as an array or a database query) and converts each entry into a view that can be added into the AdapterViewlayout.

当您的布局的内容是动态的还是不预先确定时,你可以使用一个布局,该布局子类 AdapterView 来填充包含在运行时视图的布局。AdapterView 类的子类使用适配器将数据绑定到其布局。适配器作为数据源和 AdapterView 布局之间一个中东人的行为方式 — — Adapter 检索数据 (如从数组或数据库查询的源),将每此输入转换到视图中,视图可以添加到 AdapterView布局。

Common layouts backed by an adapter include:

通过适配器返回的普通布局包括:

List View

Displays a scrolling single column list.

显示滚动单个列表

Grid View

Displays a scrolling grid of columns and rows.

显示滚动列和行格

List View

Displays a scrolling single column list.

Grid View

Displays a scrolling grid of columns and rows.

Filling an adapter view with data

You can populate an AdapterView such as ListView orGridView by binding the AdapterView instance to an Adapter, which retrieves data from an external source and creates a Viewthat represents each data entry.

您可以使用填充 AdapterView比如ListView orGridView,通过将AdapterView绑定到AdapterAdapter其中从外部源检索数据,并创建 View表示每个数据输入。

Android provides several subclasses of Adapter that are useful for retrieving different kinds of data and building views for an AdapterView. The two most common adapters are:

android提供很多Adapter子类,这些子类对检索不同类型数据和绑定视图到AdapterView是很有用的。两个最常用的adapters是:

ArrayAdapter

Use this adapter when your data source is an array. By default, ArrayAdapter creates a view for each array item by calling toString() on each item and placing the contents in a TextView.

当您的数据源是数组时,请使用此适配器。默认情况下,ArrayAdapter 通过在每个项目上调用 tostring () 来创建为每个数组项的视图和往 TextView 中放置内容。

For example, if you have an array of strings you want to display in a ListView, initialize a new ArrayAdapterusing a constructor to specify the layout for each string and the string array:

例如,如果您有您想要在列表视图中显示的字符串的数组,初始化新的 ArrayAdapter,用它来构造函数来指定的布局的每个字符串和字符串数组:

ArrayAdapter adapter =newArrayAdapter<String>(this,android.R.layout.simple_list_item_1, myStringArray);

The arguments for this constructor are:

· Your app Context

· The layout that contains a TextViewfor each string in the array

· The string array

Then simply callsetAdapter() on your ListView:

在ListView中简单的调用setAdapter()。

ListView listView =(ListView) findViewById(R.id.listview);

listView.setAdapter(adapter);

To customize the appearance of each item you can override the toString() method for the objects in your array. Or, to create a view for each item that's something other than a TextView (for example, if you want anImageView for each array item), extend the ArrayAdapter class and override getView()to return the type of view you want for each item.

为了每个项的外观进行自定义,可以在您的数组重写 tostring () 方法的对象。或者,要为每个项目创建一个视图,不是 TextView (例如,如果您想为每个数组项创建 ImageView)、 扩展 ArrayAdapter 类,重写 getView () ,返回你想要为每个项目的视图返回的类型。

SimpleCursorAdapter

Use this adapter when your data comes from a Cursor. When using SimpleCursorAdapter, you must specify a layout to use for each row in the Cursor and which columns in the Cursorshould be inserted into which views of the layout. For example, if you want to create a list of people's names and phone numbers, you can perform a query that returns a Cursor containing a row for each person and columns for the names and numbers. You then create a string array specifying which columns from the Cursoryou want in the layout for each result and an integer array specifying the corresponding views that each column should be placed:

使用此适配器,当您的数据来自于游标。当使用 SimpleCursorAdapter 时,您必须指定一个布局去为每个行使用在游标中,在游标中列需要插入布局视图。例如,如果您想要创建一个人的姓名和电话号码的列表,您可以执行一个查询,返回游标包含的每一个人的行和列的名称和号码。然后,创建一个字符串数组,指定从 Cursor来的哪些列你想要在每个结果的布局和整数数组中指定相应的每个列需要被放置的视图。

String[] fromColumns ={

ContactsContract.Data.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER

};

int[] toViews ={

R.id.display_name, R.id.phone_number

};

When you instantiate the SimpleCursorAdapter, pass the layout to use for each result, the Cursor containing the results, and these two arrays:

当你实例化 SimpleCursorAdapter 时,传递要使用的每个结果,即游标包含的结果和这些两个数组给布局:

SimpleCursorAdapter adapter =newSimpleCursorAdapter(

this, R.layout.person_name_and_number, cursor, fromColumns, toViews,0);

ListView listView = getListView();

listView.setAdapter(adapter);

The SimpleCursorAdapter then creates a view for each row in theCursor using the provided layout by inserting each fromColumns item into the corresponding toViewsview.

然后SimpleCursorAdapter 为在游标中的每个行创建一个视图。通过将每个 fromColumns 项目插入到相应的 toViews中来使用提供的布局

If, during the course of your application's life, you change the underlying data that is read by your adapter, you should call notifyDataSetChanged(). This will notify the attached view that the data has been changed and it should refresh itself.

如果在您的应用程序的生命的过程,更改读取自适配器的基础数据,您应调用 notifyDataSetChanged()。这将通知附加的视图,数据已更改,它应该刷新自己。

Handling click events

You can respond to click events on each item in an AdapterView by implementing the AdapterView.OnItemClickListenerinterface. For example:

在AdapterView中,您可以响应每个项目的单击事件中通过执行 AdapterView.OnItemClickListener接口例如:

// Create a message handling object as an anonymous class.

private OnItemClickListener

mMessageClickedHandler =newOnItemClickListener(){

public void onItemClick(AdapterView parent,View v,int position,long id){

// Do something in response to the click}

};

listView.setOnItemClickListener(mMessageClickedHandler);

转载于:https://my.oschina.net/u/936871/blog/130820

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值