Use of the Android adapter (Arrayadapter, Simpleadapter, Baseadapter)

Source: Internet
Author: User

Directory

    • Array Adapter Arrayadapter
    • Simple Adapter Simpleadapter
    • Custom Adapter Baseadapter

Array adapter Arrayadapter

Brief introduction:

Arrayadapter is a list adapter for Android that is used to fit the control between this type of ListView and the data.
The default Arrayadapter expects the accepted style file to contain only a single TextView

How to use:
Achieve the following effects:


XML layout:
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">      <ListViewAndroid:id= "@+id/li"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"></ListView></LinearLayout>

Java code:
Package Com.contentprovide.liuliu.demo_01;import Android.support.v7.app.appcompatactivity;import Android.os.bundle;import Android.view.view;import Android.widget.adapterview;import Android.widget.ArrayAdapter; Import Android.widget.listview;import Android.widget.textview;import Android.widget.toast;public class MainActivity    Extends Appcompatactivity {arrayadapter<string> arrayadapter;    ListView Li;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Li = (ListView) Findviewbyid (r.id.li);arrayadapter = new Arrayadapter (mainactivity.this,r.layout.support_simple_spinner_dropdown_item);Add Content Arrayadapter.add ("1") to the array adapter;        Arrayadapter.add ("2");        Arrayadapter.add ("3"); Arrayadapter.add ("4");//Add the array adapter to the ListView objectLi.setadapter (arrayadapter);Add a click event to the ListView object: Click on each textview option to eject the corresponding content on the text box Li.setonitemclicklistener (new Adapterview.onitemclicklistener ()                {@Override public void Onitemclick (adapterview<?> adapterview, view view, int I, long l) {                TextView t = (TextView) view;                String s = T.gettext (). toString ();            Toast.maketext (Getapplicationcontext (), S,toast.length_short). Show ();    }        }); }}



Simple Adapter Simpleadapter

Custom Adapter Baseadapter

Use of the Android adapter (Arrayadapter, Simpleadapter, Baseadapter)

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.