Mainpage. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: Orientation = "vertical">
<Textview
Android: Id = "@ + ID/textview1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "large text"
Android: textappearance = "? Android: ATTR/textappearancelarge "/>
<Gridview xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Id = "@ + ID/gridview"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: padding = "10dp"
Android: verticalspacing = "10dp"
Android: horizontalspacing = "10dp"
Android: numcolumns = "auto_fit"
Android: columnwidth = "60dp"
Android: stretchmode = "columnwidth"
Android: gravity = "center"
/>
</Linearlayout>
Icon_item.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_height = "wrap_content"
Android: paddingbottom = "4dip" Android: layout_width = "fill_parent">
<Imageview
Android: layout_height = "65dp"
Android: layout_width = "65dp"
Android: Id = "@ + ID/itemimage"
Android: layout_centerhorizontal = "true">
</Imageview>
<Textview
Android: layout_width = "wrap_content"
Android: layout_below = "@ + ID/itemimage"
Android: layout_height = "wrap_content"
Android: text = "textview01"
Android: layout_centerhorizontal = "true"
Android: Id = "@ + ID/itemtext">
</Textview>
</Relativelayout>
Mainpageactivity
Package Android. ERP;
Import java. util. arraylist;
Import java. util. hashmap;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. util. log;
Import Android. View. view;
Import Android. widget. adapterview;
Import Android. widget. adapterview. onitemclicklistener;
Import Android. widget. gridview;
Import Android. widget. simpleadapter;
Public class mainpageactivity extends activity {
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. mainpage );
Createshucut ();
}
// Generate shortcuts
Void createshucut ()
{
Gridview = (gridview) findviewbyid (R. Id. gridview );
// Generate dynamic array and transfer data
Arraylist Lstimageitem. Add (getIcon ("my address book", R. drawable. inco_1 ));
Lstimageitem. Add (getIcon ("My course schedule", R. drawable. inco_5 ));
Lstimageitem. Add (getIcon ("exit", R. drawable. inco_4 ));
// Generate the imageitem of the adapter <====> dynamic array elements, one-to-one correspondence between the two
Simpleadapter saimageitems = new simpleadapter (this, // No explanation
Lstimageitem, // Data Source
R. layout. icon_item, // XML Implementation of night_item
// Subitem of the dynamic array and imageitem
New String [] {"itemimage", "itemtext "},
// An imageview in the XML file of imageitem, two textview IDS
New int [] {R. Id. itemimage, R. Id. itemtext });
// Add and display
Gridview. setadapter (saimageitems );
// Add Message Processing
Gridview. setonitemclicklistener (New itemclicklistener ());
}
Hashmap <string, Object> getIcon (string icontitle, int drawableiconid)
{
Hashmap <string, Object> map = new hashmap <string, Object> ();
Map. Put ("itemimage", drawableiconid); // Add the ID of the image resource.
Map. Put ("itemtext", icontitle); // itemtext by serial number
Return map;
}
Class itemclicklistener implements onitemclicklistener
{
Public void onitemclick (adapterview <?> Arg0, // The adapterview where the click happened
View arg1, // The view within the adapterview that was clicked
Int arg2, // The Position of the view in the adapter
Long arg3 // The row ID of the item that was clicked
){
// Arg2 = arg3
Hashmap <string, Object> item = (hashmap <string, Object>) arg0.getitematposition (arg2 );
// Display the itemtext of the selected item
Settitle (string) item. Get ("itemtext "));
String title = (string) item. Get ("itemtext ");
Switchmoudel (title );
}
// Enter the specified Module
Void switchmoudel (string strtitle)
{
If (strtitle. Revoke signorecase ("My course schedule "))
Entermoudel (myclasslistactivity. Class );
If (strtitle. inclusignorecase ("my address book "))
Entermoudel (contactbooklistactivity. Class );
If (strtitle. Revoke signorecase ("quit "))
{
Log. D ("activity count:", activitylist. Size () + "");
Quitsystem ();
}
}
// Enter the specified module strtitle: Module name, enteractivityname: Enter the activityh name
Void entermoudel (class <?> Enteractivityname)
{
Intent intent = new intent (mainpageactivity. This, enteractivityname );
Startactivity (intent );
}
}
}