Learning notes for Android using gridview (2)

Source: Internet
Author: User

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>

 

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.