Android's Arrayadaper app

Source: Internet
Author: User

ListView Page Layout: Layout/activity_main.xml:

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= "Com.example.day_05_022.MainActivity" >


<listview
Android:id= "@+id/lvmonths"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:divider= "#ccc"
android:dividerheight= "6DP"/>


</RelativeLayout>

Java code in this layout:

Package com.example.day_05_022;


Import android.support.v7.app.ActionBarActivity;
Import Android.os.Bundle;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.widget.ArrayAdapter;
Import Android.widget.BaseAdapter;
Import Android.widget.ListView;


public class Mainactivity extends Actionbaractivity {
Private ListView lvmonths;//listview Object
Private Baseadapter Arrayadapter;//Adapter
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Init ();
}


private void init () {
TODO auto-generated Method Stub
//Initialize the ListView object
Lvmonths = (ListView) Findviewbyid (r.id.lvmonths);
//Initialize the Arrayadaper object

/Focus EXPLANATION The first parameter is the activity object where the layout is to be displayed, the second parameter is the physical address of the collection data to be displayed, and the third parameter is

refers to the appropriate layout page, where Android comes directly with the layout

Arrayadapter = Arrayadapter.createfromresource (This,
R.array.day_of_week,
Android. R.layout.simple_expandable_list_item_1);
Setting up the adapter
Lvmonths.setadapter (Arrayadapter);
}



}

String string resource: Values/strings.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>


<string name= "App_name" >Day_05_022</string>
<string name= "Hello_world" >hello world!</string>
<string name= "Action_settings" >Settings</string>
<string-array name= "Day_of_week" >
<item >Sunday</item>
<item>Monday</item>
<item>Tuesday</item>
<item>Wednesday</item>
<item>Thursday</item>
<item>Friday</item>
<item>Saturday</item>

</string-array>
</resources>

Effect:

650) this.width=650; "src=" http://img.blog.csdn.net/20141130102436889 "/>

This article from "Follow the heart of the other side" blog, declined reprint!

Android Arrayadaper app

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.