Android Common Controls Simpleadapter and list

Source: Internet
Author: User
Tags resource

First, Simpleadapter

Simpleadapter is a simple adapter that maps static data to a defined view in an XML file. You can specify a list of data support such as the ArrayList composition map. 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 defines the rows to be displayed, mapped to the specified view by keyword.

Constructors

Public Simpleadapter (context, list<? extends Map<string,?>> data, int resource, string[] from, int[] To)

Parameters

Context associated with Simpleadapter the view in which it is running.

Data a list of maps. Each entry in the list corresponds to a row in the list and should contain all the entries specified in from

Resource A resource unique identification that defines a view layout for a list item. The layout file should contain at least what names are defined in to.

A list of column names that will be added to the map to associate each item

To the view that the column should be displayed in the parameter from. These should all be textview. The initial n view in the list is the value obtained from the original n column in the parameter from.

A simlpleadapter is working like this. Suppose the simpleadapter is used for ListView. Then each list item in the ListView is the layout specified by the resource parameter value. The data parameter is what you want to load into the ListView. Let's look at each list item first, assuming that the list item's corresponding layout file contains two components: TextView and Edittext,id are TextView and EditText respectively. When you load a list item, you need to match the component's ID and the map object in the list element in the data argument. Therefore, the from parameter map object's key, while to represents the component's ID, for example, the parameter value in this example is from = new string[]{"UserId", "userName"},to = new int[]{ R.id.userid,r.id.username}. The meaning is to bind the value of the key in the Map object to the R.id.userid, username is similar to the UserID. Now look at the data parameter, a ListView consists of multiple list items. Each list item provides data by a map object, and multiple list items provide multiple map objects from the list object.

Second, ListView

ListView is a more commonly used component in Android development, showing specific content in a list and being able to display it adaptively according to the length of the data.

The display of the list requires three elements:

1. Listveiw is used to show the view of the list.

2. Adapters are used to map data to mediations on ListView.

3. Data specific to the string, picture, or basic component that will be mapped.

Depending on the adapter type of the list, the list is divided into three categories, Arrayadapter,simpleadapter and Simplecursoradapter. One of the most simple to arrayadapter, can only show a line of words. Simpleadapter has the best extensibility and can be customized to a variety of effects. Simplecursoradapter can be considered as a simple combination of the Simpleadapter database, you can use the contents of the database as a list of the form of display. Simpleadapter inherits from Adapterview. We can add listeners to ListView through the Setonitemclicklistener () method, when the user clicks on a list item to perform the appropriate action. Replication of public abstract void Onitemclick (adapterview<?> parent, view view, int position, long id) method is required in the listener.

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.