Simpleadapter and listview

Source: Internet
Author: User

Reference: http://www.bianceng.cn/ OS /extra/201106/27059.htm

1. simpleadapter

Simpleadapter is a simple adapter that maps static data to a view defined in an XML file. You can specify a list supported by data, such as a map composed of arraylist. Each entry in the arraylist corresponds to a row in the list. Maps contains each row of data. You can specify a view XML file that is used to display rows and map it to the specified view using keywords.

Constructor

Public simpleadapter (context, list <? Extends Map <string,?> Data, int resource, string [] From, int [])

Parameters

Context associates with the context of the view running on simpleadapter.

A list of data maps. Each entry in the list corresponds to a row in the list, which should contain all the entries specified in the from

Resource: the unique identifier of a resource that defines the view layout of a list item. The layout file should contain at least the names defined in.

From a list of column names that will be added to map associated with each project

To should display the column view in the FROM parameter. All of these should be textview. The initial n view in the list is the value obtained from the initial n column of the from parameter.

A simlpleadapter works like this. Assume that simpleadapter is used for listview. Then, each list item in listview is the layout specified by the resource parameter value. The data parameter is the data to be loaded into the listview. Let's first look at each list item. Assume that the layout file corresponding to the list item contains two components: textview and edittext, with the ID textview and edittext respectively. When loading a list item, you must use the component ID and the map object in the list element in the Data parameter. Therefore, the from parameter is the key of the map object, and to indicates the component ID. For example, the parameter value in this example
It is from = new string [] {"userid", "username"}, To = new int [] {R. Id. userid, R. Id. Username }. This means to bind the value of key userid in the map object to R. Id. userid, And the username is similar. Now let's look at the data parameter. A listview consists of multiple list items. Each list item provides data by a map object, while multiple column table items provide multiple map objects by the list object.

Ii. listview

In Android development, listview is a commonly used component that displays specific content in the form of a list and can be automatically displayed based on the length of data.

The display of the list requires three elements:

1. listveiw is used to display the view of the list.

2. the adapter is used to map data to the mediation on the listview.

3. The specific string, image, or basic component of the data to be mapped.

Based on the list of adapter types, the list is divided into three types: arrayadapter, simpleadapter, and simplecursoradapter. Arrayadapter is the simplest and can only display one line of words. Simpleadapter has the best scalability and Can Customize various effects. Simplecursoradapter can be considered as a simple combination of simpleadapter on the database. It can display the database content in the form of a list. Simpleadapter inherits from adapterview. You can add a listener to the listview by using the setonitemclicklistener () method. When a user clicks a list
. In the listener, public abstract void onitemclick (adapterview <?> Parent, view, int position, long ID) method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.