The last time is different:
Each image contains a text message.
This example is to implement this function. Another point is that the previous method is to implement an imageadapter to inherit the baseadapter and then use it for the gridview.
The usage of the gridview described in this article is very similar to that of the previous listview. Using the adapter simpleadapter, my citrus is quite simple.
Package xiaosi. gridview; import Java. util. arraylist; import Java. util. hashmap; import android. app. activity; import android. OS. bundle; import android. view. view; import android. widget. adapterview; import android. widget. adapterview. onitemclicklistener; import android. widget. gridview; import android. widget. simpleadapter; public class gridviewactivity extends activity {/** called when the activity is first creat Ed. */private gridview = NULL; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); gridview = (gridview) findviewbyid (R. id. gridview); // generate a data source list arraylist
Main. xml
<?xml version="1.0" encoding="utf-8"?><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:verticalSpacing="5dip" android:horizontalSpacing="5dip" android:columnWidth="80dip" android:numColumns="auto_fit" android:stretchMode="columnWidth" android:gravity="center" />
Create 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="wrap_content" android:id="@+id/ItemImage" android:layout_width="wrap_content" 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>