Android UI-nine-square Implementation of android

Source: Internet
Author: User

Xml code:
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: app = "http://schemas.android.com/apk/res/com.google.android.gx5weather"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_weight = "1.0"
Android: background = "@ drawable/bg"
>
<ImageView android: id = "@ + id/ImageView01"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_vertical"
Android: background = "@ drawable/top"> </ImageView>
<GridView xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/gridview"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: numColumns = "3"
Android: verticalSpacing = "30dip"
Android: horizontalSpacing = "10dip"
Android: columnWidth = "90dip" // column width
Android: stretchMode = "columnWidth"
Android: gravity = "center"
Android: listSelector = "@ drawable/grid_selector_background"
>
</GridView>
</LinearLayout>

 
Android: numColumns = "3" // automatic when the number of columns in the nine cells is auto_fit
Android: listSelector = "@ drawable/grid_selector_background" // background of the jiugong lattice. You can find a rounded corner square.


 

Public class NineBox extends Activity {

/** Called when the activity is first created .*/

@ Override

Protected void onCreate (Bundle savedInstanceState ){

// TODO Auto-generated method stub

Super. onCreate (savedInstanceState );

This. requestWindowFeature (Window. FEATURE_NO_TITLE );

This. getWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN,

WindowManager. LayoutParams. FLAG_FULLSCREEN );

 

SetContentView (R. layout. main_activity );

GridView gridview = (GridView) findViewById (R. id. gridview );

ArrayList <HashMap <String, Object> lstImageItem = new ArrayList <HashMap <String, Object> ();

For (int I = 1; I <10; I ++)

{

HashMap <String, Object> map = new HashMap <String, Object> ();

If (I = 1 ){

Map. put ("ItemImage", R. drawable. g11 );

Map. put ("ItemText", getResources (). getString (R. string. gridview1 ));

}

If (I = 2 ){

Map. put ("ItemImage", R. drawable. g12 );

Map. put ("ItemText", getResources (). getString (R. string. gridview2 ));

}

If (I = 3 ){

Map. put ("ItemImage", R. drawable. g13 );

Map. put ("ItemText", getResources (). getString (R. string. gridview3 ));

}

If (I = 4 ){

Map. put ("ItemImage", R. drawable. g14 );

Map. put ("ItemText", getResources (). getString (R. string. gridview4 ));

}

If (I = 5 ){

Map. put ("ItemImage", R. drawable. g15 );

Map. put ("ItemText", getResources (). getString (R. string. gridview5 ));

}

If (I = 6 ){

Map. put ("ItemImage", R. drawable. g16 );

Map. put ("ItemText", getResources (). getString (R. string. gridview6 ));

}

If (I = 7 ){

Map. put ("ItemImage", R. drawable. g17 );

Map. put ("ItemText", getResources (). getString (R. string. gridview7 ));

}

If (I = 8 ){

Map. put ("ItemImage", R. drawable. g18 );

Map. put ("ItemText", getResources (). getString (R. string. gridview8 ));

}

If (I = 9 ){

Map. put ("ItemImage", R. drawable. g19 );

Map. put ("ItemText", getResources (). getString (R. string. gridview9 ));

}

LstImageItem. add (map );

 

}

 


SimpleAdapter saImageItems = new SimpleAdapter (this,

LstImageItem,

R. layout. grid_item,

New String [] {"ItemImage", "ItemText "},

New int [] {R. id. ItemImage, R. id. ItemText });

 

Gridview. setAdapter (saImageItems );

Gridview. setOnItemClickListener (new ItemClickListener ());

}

 

 

Class ItemClickListener implements OnItemClickListener

{

 


@ SuppressWarnings ("unchecked ")

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

){

 

HashMap <String, Object> item = (HashMap <String, Object>) arg0.getItemAtPosition (arg2 );

 

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview1 ))){

Toast. makeText (NineBox. this, R. string. gridview1, Toast. LENGTH_LONG). show ();

}

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview2 ))){

Toast. makeText (NineBox. this, R. string. gridview2, Toast. LENGTH_LONG). show ();

}

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview3 ))){

Toast. makeText (NineBox. this, R. string. gridview3, Toast. LENGTH_LONG). show ();

}

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview4 ))){

Toast. makeText (NineBox. this, R. string. gridview4, Toast. LENGTH_LONG). show ();

}

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview5 ))){

Toast. makeText (NineBox. this, R. string. gridview5, Toast. LENGTH_LONG). show ();

}

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview6 ))){

Toast. makeText (NineBox. this, R. string. gridview6, Toast. LENGTH_LONG). show ();

}

 


If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview7 ))){

Toast. makeText (NineBox. this, R. string. gridview7, Toast. LENGTH_LONG). show ();

}

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview8 ))){

Toast. makeText (NineBox. this, R. string. gridview8, Toast. LENGTH_LONG). show ();

}

If (item. get ("ItemText"). equals (getResources (). getString (R. string. gridview9 ))){

Toast. makeText (NineBox. this, R. string. gridview9, Toast. LENGTH_LONG). show ();

}

}

}

}

 
Author: LuoXianXion
 
 

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.