Advertisement
cheswe

Arrays

Dec 28th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. package wks.android;
  2.  
  3. import java.util.Arrays;
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.content.pm.ActivityInfo;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.view.Window;
  12. import android.view.WindowManager;
  13. import android.view.View.OnClickListener;
  14. import android.widget.Button;
  15. import android.widget.ImageView;
  16. import android.widget.TextView;
  17.  
  18. public class GameFindActivity extends Activity {
  19. private int total=7;
  20. private Button[] number_btn = {null,null,null,null,null,null,null};
  21. private int[] btn = {R.id.button1,R.id.button2,R.id.button3,R.id.button4,
  22. R.id.button5,R.id.button6,R.id.button7};
  23. private ImageView[] iv = {null,null,null,null,null,null,null};
  24. private TextView tv1;
  25.  
  26. /** Called when the activity is first created. */
  27. public void onCreate(Bundle savedInstanceState) {
  28. super.onCreate(savedInstanceState);
  29.  
  30. requestWindowFeature(Window.FEATURE_NO_TITLE);
  31. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
  32. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  33. setContentView(R.layout.gamefind);
  34.  
  35. tv1 = (TextView)findViewById( R.id.textView1 );
  36.  
  37. number_btn [0] = (Button)findViewById( R.id.button1 );
  38. number_btn [1] = (Button)findViewById( R.id.button2 );
  39. number_btn [2] = (Button)findViewById( R.id.button3 );
  40. number_btn [3] = (Button)findViewById( R.id.button4 );
  41. number_btn [4] = (Button)findViewById( R.id.button5 );
  42. number_btn [5] = (Button)findViewById( R.id.button6 );
  43. number_btn [6] = (Button)findViewById( R.id.button7 );
  44.  
  45. iv [0] = (ImageView)findViewById( R.id.imageView1 );
  46. iv [1] = (ImageView)findViewById( R.id.imageView2 );
  47. iv [2] = (ImageView)findViewById( R.id.imageView3 );
  48. iv [3] = (ImageView)findViewById( R.id.imageView4 );
  49. iv [4] = (ImageView)findViewById( R.id.imageView5 );
  50. iv [5] = (ImageView)findViewById( R.id.imageView6 );
  51. iv [6] = (ImageView)findViewById( R.id.imageView7 );
  52.  
  53. for(int i = 0 ; i < number_btn.length ; i ++ )
  54. {
  55. number_btn[i].setOnClickListener( number_event ) ;
  56. }
  57. }
  58.  
  59.  
  60. private OnClickListener number_event = new OnClickListener()
  61. {
  62. public void onClick( View v )
  63. {
  64. total--;
  65. tv1.setText("目前剩" + String.valueOf(total) + "個");
  66. iv[Arrays.binarySearch(btn, v.getId())].setVisibility(View.VISIBLE);
  67. ((Button)v).layout(0, 0, 0, 0);
  68. if(total == 0)
  69. {
  70. tv1.setText("已全找到:D");
  71. Intent intent = new Intent() ;
  72. intent.setClass(GameFindActivity.this, GameFind2Activity.class) ;
  73. startActivity(intent) ;
  74. }
  75. }
  76. };
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement