Android Gallery Application

Source: Internet
Author: User


Package bizhi. co. cc;

Import java. io. InputStream;

Import net. miidi. credit. MiidiCredit;
Import android. app. Activity;
Import android. app. AlertDialog;
Import android. content. Context;
Import android. content. DialogInterface;
Import android. content. res. Resources;
Import android. content. res. TypedArray;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. view. ViewGroup;
Import android. view. Window;
Import android. view. WindowManager;
Import android. widget. AdapterView;
Import android. widget. BaseAdapter;
Import android. widget. Gallery;
Import android. widget. ImageView;

Public class BizhiActivity extends
Activity {
Protected static InputStream iStream;
Private ImageAdapter mImageAdapter;
ImageView mImageView;
Private int [] image = {
R. drawable. shuzi1,
R. drawable. shuzi18,
R. drawable. shuzi2,
R. drawable. shuzi3,
R. drawable. shuzi4,
R. drawable. shuzi5,
R. drawable. shuzi6,
R. drawable. shuzi7,

R. drawable. shuzi9,
R. drawable. shuzi10,
R. drawable. shuzi11,
R. drawable. shuzi12,
R. drawable. shuzi13,
R. drawable. shuzi14,
R. drawable. shuzi15,
R. drawable. shuzi16,
R. drawable. shuzi17,

R. drawable. shuzi19,
R. drawable. shuzi20,

};

/** Called when the activity is first created .*/
@ Override
Public void onCreate (
Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
RequestWindowFeature (Window. FEATURE_NO_TITLE );
GetWindow ()
. SetFlags (
WindowManager. LayoutParams. FLAG_FULLSCREEN,
WindowManager. LayoutParams. FLAG_FULLSCREEN );
MiidiCredit. init (BizhiActivity. this, "5677 ",
"Iuwruztprel0txtd", false );
SetContentView (R. layout. main );
MImageAdapter = new ImageAdapter (
BizhiActivity. this,
Image );

Gallery mGallery = (Gallery) findViewById (R. id. gallery1 );
MImageView = (ImageView) findViewById (R. id. imageView1 );

// Int mGalleryItemBackground;
// TypedArray a = obtainStyledAttributes (R. styleable. Gallery );
// MGalleryItemBackground = a. getResourceId (
// R. styleable. Gallery_android_galleryItemBackground, 0 );
// A. recycle ();
// MImageView. setBackgroundResource (mGalleryItemBackground );

MGallery. setAdapter (mImageAdapter );
MGallery. setOnItemClickListener (new Gallery. OnItemClickListener (){

@ Override
Public void onItemClick (
AdapterView <?> Arg0,
View arg1,
Int arg2, long arg3 ){
// TODO Auto-generated method stub
MImageView
. SetImageResource (mImageAdapter. image [arg2]);
Resources resources = getBaseContext ()
. GetResources ();
IStream = resources
. OpenRawResource (mImageAdapter. image [arg2]);

}
});

MImageView
. SetOnClickListener (new OnClickListener (){

@ Override
Public void onClick (
View v ){
// TODO Auto-generated method stub
New AlertDialog. Builder (
BizhiActivity. this)
. SetTitle (
"Correct answer :")
. SetMessage (
R. string. daan)
. SetPositiveButton (
"OK ",
New DialogInterface. OnClickListener (){

@ Override
Public void onClick (
DialogInterface dialog,
Int which ){
// TODO Auto-generated method
// Stub

}
})

. Create ()
. Show ();

}
});

}

Public class ImageAdapter extends
BaseAdapter {

Private Context context;
Private int [] image;
Int mGalleryItemBackground;

Public ImageAdapter (Context c,
Int [] image2 ){
This. context = c;
This. image = image2;

TypedArray a = obtainStyledAttributes (R. styleable. Gallery );
MGalleryItemBackground =
. GetResourceId (
R. styleable. Gallery_android_galleryItemBackground,
0 );
A. recycle ();
}

@ Override
Public int getCount (){
// TODO Auto-generated method stub
Return image. length;
}

@ Override
Public Object getItem (int arg0 ){
// TODO Auto-generated method stub
Return null;
}

@ Override
Public long getItemId (int arg0 ){
// TODO Auto-generated method stub
Return arg0;
}

@ Override
Public View getView (int arg0,
View arg1,
ViewGroup arg2 ){
// TODO Auto-generated method stub
/* Generate an ImageView object */
ImageView I = new ImageView (
Context );
/* Set the image to the imageView object */
I. setImageResource (image [arg0]);
/* Reset the width and height of the image */
I. setScaleType (ImageView. ScaleType. FIT_XY );
/* Reset the width and height of Layout */
I. setLayoutParams (new Gallery. LayoutParams (
210,190); www.2cto.com

/* Set the Gallery background image */
I. setBackgroundResource (mGalleryItemBackground );
/* Return the imageView object */
Return I;
}

}

// Public void setWallpaper (InputStream data) throws IOException {
/// TODO Auto-generated method stub
// Super. setWallpaper (data );
//}

 

By gongzibai

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.