Use ArrayAdapter for android (12) and androidadapter

Source: Internet
Author: User

Use ArrayAdapter for android (12) and androidadapter

ArrayAdapter, simpleAdapter, SimpleCursorAdapter, and BaseAdapter are commonly used.

1. ArrayAdapter is usually used to wrap multiple values of an array or List set into multiple List items.

Arrayadapter layout file:

<span style="font-size:18px;"><?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" >    <ListView        android:id="@+id/lv_arrayadapter"        android:layout_width="fill_parent"        android:layout_height="wrap_content" >    </ListView></LinearLayout></span>

ArrayAdapterTest file:

<Span style = "font-size: 18px;"> public class ArrayAdapterTest extends Activity {private ListView lv_arrayadapter; private String [] str_name = new String [] {"jack ", "debb", "robin", "kikt", "dog", "cat", "elep"}; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. arrayadapter); initView (); setData ();} private void initView () {lv_arrayada Pter = (ListView) findViewById (R. id. lv_arrayadapter); // register the listener event lv_arrayadapter.setOnItemClickListener (new OnItemClickListener () {@ Overridepublic void onItemClick (AdapterView <?> Parent, View view, int position, long id) {Toast. makeText (ArrayAdapterTest. this, str_name [position], Toast. LENGTH_SHORT ). show () ;}}) ;}private void setData () {// create ArrayAdapterArrayAdapter <String> arrayAdapter = new ArrayAdapter <String> (ArrayAdapterTest. this, android. r. layout. simple_list_item_1, str_name); // bind the adapter lv_arrayadapter.setAdapter (arrayAdapter) ;}</span>


The three parameters specified during ArrayAdapter creation are described as follows:

Contex: Context of the entire application.

TextViewResourceId: Resource ID, representing a TextView, used as the list component of ArrayAdapter.

Objects: data in the list item




Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42353249 sentiment control _





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.