PackageCom.example.puke;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {PrivateImageView img1; PrivateImageView Img2; PrivateImageView IMG3; PrivateTextView Show; Private int[] IMGs ={r.drawable.a1, r.drawable.a2, r.drawable.a3}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); IMG1=(ImageView) Findviewbyid (R.ID.IMG1); Img2=(ImageView) Findviewbyid (R.ID.IMG2); IMG3=(ImageView) Findviewbyid (R.ID.IMG3); Show=(TextView) Findviewbyid (r.id.show); Setimg (); Img1.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {img1.setimageresource (imgs[0]); Img2.setimageresource (imgs[1]); Img3.setimageresource (imgs[2]); if(Imgs[0] = =r.drawable.a2) {Show.settext ("Bingo"); }Else{Show.settext ("Error"); } //setting the degree of ambiguityImg2.setalpha (100); Img3.setalpha (100); } }); Img2.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {img1.setimageresource (imgs[0]); Img2.setimageresource (imgs[1]); Img3.setimageresource (imgs[2]); if(Imgs[1] = =r.drawable.a2) {Show.settext ("Bingo"); }Else{Show.settext ("Error"); } img1.setalpha (100); Img3.setalpha (100); } }); Img3.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {img1.setimageresource (imgs[0]); Img2.setimageresource (imgs[1]); Img3.setimageresource (imgs[2]); if(Imgs[2] = =r.drawable.a2) {Show.settext ("Bingo"); }Else{Show.settext ("Error"); } img2.setalpha (100); Img1.setalpha (100); } }); Findviewbyid (R.id.reset). Setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method Stubsetimg (); Img1.setimageresource (R.DRAWABLE.A4); Img2.setimageresource (R.DRAWABLE.A4); Img3.setimageresource (R.DRAWABLE.A4); Img1.setalpha (255); Img2.setalpha (255); Img3.setalpha (255); Show.settext (""); } }); } //Random Change Private voidsetimg () { for(inti = 0; i < imgs.length; i++) { inttemp =Imgs[i]; intin = (int) (Math.random () * 2); Imgs[i]=Imgs[in]; Imgs[in]=temp; } }}
Layout
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Looking for Hearts a"Android:textcolor= "@android: Color/secondary_text_dark"android:textsize= "30SP"android:layout_gravity= "Center_horizontal" /> <TextViewAndroid:id= "@+id/show"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"android:textsize= "15SP"android:layout_gravity= "Center_horizontal" /> <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal"Android:layout_margintop= "50DP" > <ImageViewAndroid:id= "@+id/img1"Android:layout_width= "0DP"Android:layout_height= "100DP"android:src= "@drawable/a4"Android:layout_weight= "1" /> <ImageViewAndroid:id= "@+id/img2"Android:layout_width= "0DP"Android:layout_height= "100DP"android:src= "@drawable/a4"Android:layout_weight= "1" /> <ImageViewAndroid:id= "@+id/img3"Android:layout_width= "0DP"Android:layout_height= "100DP"android:src= "@drawable/a4"Android:layout_weight= "1" /> </LinearLayout> <ButtonAndroid:id= "@+id/reset"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Shuffle"android:layout_gravity= "Center_horizontal"Android:layout_margintop= "50DP" /></LinearLayout>
Guess a game of Red Peach