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