The implementation method of the Android nine Sudoku _android

Source: Internet
Author: User

1. XML code:

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
Android:layout_weight= "1.0"
android:background= "@drawable/yellow"
>
<imageview android:id= "@+id/imageview01"
Android:layout_width= "100SP"
android:layout_height= "100SP"
Android:layout_gravity= "Center_vertical"
Android:background= "@drawable/A" ></ImageView>
<gridview
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"
Android:stretchmode= "ColumnWidth"
android:gravity= "Center"
Android:listselector= "@drawable/C"
>
</GridView>
</LinearLayout>

where android:numcolumns= "3" represents the number of columns for the nine Sudoku Auto_fit automatically

2, implementation code

Copy Code code as follows:

public class Mainactivity extends activity {

/** called the activity is a. */

@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setup screen does not have a title
This.requestwindowfeature (Window.feature_no_title);
Remove title bar
This.getwindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Setcontentview (R.layout.activity_main);

GridView GridView = (GridView) Findviewbyid (R.id.gridview);
Create an array list object
arraylist
/**
* Add content to each grid
*/
for (int i = 1; i < i++) {
hashmap<string, object> map = new hashmap<string, object> ()//Create HashMap 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);
}

/**
* Establish a Simpleadapter adapter for the GridView
*/
The five parameters in Simpleadapter () are: The first context, the second data resource, the third, the layout file for each subkey, and the key array in each of the fourth subkeys.
The value array in each of the fifth subkeys
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);//Add Adapter
Gridview.setonitemclicklistener (New Itemclicklistener ());//Set up a listener for each subkey
}

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 is clicked
int arg2,//The position of the view in the adapter
Long arg3//the row ID of the item that is clicked
) {
hashmap<string, object> item = (hashmap<string, object>) arg0
. Getitematposition (ARG2);
if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.string.gridview1))) {
Toast.maketext (Mainactivity.this, R.string.gridview1,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW2))) {
Toast.maketext (Mainactivity.this, R.string.gridview2,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW3))) {
Toast.maketext (Mainactivity.this, R.STRING.GRIDVIEW3,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW4))) {
Toast.maketext (Mainactivity.this, R.STRING.GRIDVIEW4,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW5))) {
Toast.maketext (Mainactivity.this, R.STRING.GRIDVIEW5,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW6))) {
Toast.maketext (Mainactivity.this, R.STRING.GRIDVIEW6,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW7))) {
Toast.maketext (Mainactivity.this, R.STRING.GRIDVIEW7,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW8))) {
Toast.maketext (Mainactivity.this, R.string.gridview8,
Toast.length_long). Show ();
}

if (Item.get ("Itemtext"). Equals (
Getresources (). getString (R.STRING.GRIDVIEW9))) {
Toast.maketext (Mainactivity.this, R.string.gridview9,
Toast.length_long). Show ();
}
}
}

}

3, the implementation of the effect as shown in the picture

Related Article

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.