Board logo

標題: 隨堂測驗0629 [打印本頁]

作者: 顏子翔    時間: 2019-6-29 10:54     標題: 隨堂測驗0629

本日隨堂測驗 107 108
作者: 黃璽安    時間: 2019-6-29 10:54

  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.TextView;

  9. public class GDD01 extends Activity
  10. {
  11.   private static final String TAG = "Android_Log";

  12.   @Override
  13.   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  14.     super.onActivityResult(requestCode, resultCode, data);
  15.     if(requestCode == 1999)
  16.       tv.setText(resultCode+" ");
  17.   }

  18.   private TextView tv;
  19.   private Button b1;
  20.   private Button b2;

  21.   @Override
  22.   public void onCreate(Bundle savedInstanceState){
  23.     super.onCreate(savedInstanceState);
  24.     setContentView(R.layout.main);

  25.     tv=(TextView) findViewById(R.id.text1);;
  26.     b1 = (Button) findViewById(R.id.button1);
  27.     b2 = (Button) findViewById(R.id.button2);

  28.     b1.setOnClickListener(new Button.OnClickListener(){
  29.       public void onClick(View v){
  30.         Intent it = new Intent(GDD01.this, GDD01_2.class);
  31.         startActivityForResult(it, 1999);
  32.       }
  33.     });

  34.     b2.setOnClickListener(new Button.OnClickListener(){
  35.       public void onClick(View v){
  36.         finish();
  37.       }
  38.     });
  39.     Log.i(TAG, "onCreate");
  40.   }

  41.   @Override
  42.   public void onStart(){
  43.     super.onStart();
  44.     Log.i(TAG, "onStart");
  45.   }
  46.   @Override
  47.   public void onResume(){
  48.     super.onResume();
  49.     Log.i(TAG, "onResume");
  50.   }
  51.   @Override
  52.   public void onPause(){
  53.     super.onPause();
  54.     Log.i(TAG, "onPause");
  55.   }
  56.   @Override
  57.   public void onStop(){
  58.     super.onStop();
  59.     Log.i(TAG, "onStop");
  60. }
  61.   @Override
  62.   public void onRestart(){
  63.     super.onRestart();
  64.     Log.i(TAG, "onRestart");
  65.   }
  66.   @Override
  67.   public void onDestroy(){
  68.     super.onDestroy();
  69.     Log.i(TAG, "onDestroy");
  70.   }
  71. }
複製代碼
  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. /**
  7. * Created by student on 2019/6/22.
  8. */
  9. public class GDD01_2 extends Activity{
  10.     @Override
  11.     public void onCreate(Bundle savedInstanceState){
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.mylayout);
  14.         Button btn = (Button) findViewById(R.id.button2);
  15.         btn.setOnClickListener(new View.OnClickListener() {
  16.             @Override
  17.             public void onClick(View v) {
  18.                 setResult(99);
  19.                 finish();
  20.             }
  21.         });
  22.     }
  23. }
複製代碼
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest
  3.   package="com.tqc.gdd01"
  4.   xmlns:android="http://schemas.android.com/apk/res/android">
  5.   <application
  6.     android:allowBackup="true"
  7.     android:icon="@mipmap/ic_launcher"
  8.     android:label="@string/app_name"
  9.     android:theme="@style/AppTheme">
  10.     <activity
  11.       android:name="com.tqc.gdd01.GDD01"
  12.       android:label="@string/app_name">
  13.       <intent-filter>
  14.         <action android:name="android.intent.action.MAIN"/>
  15.         <category android:name="android.intent.category.LAUNCHER"/>
  16.       </intent-filter>
  17.     </activity>
  18.     <activity android:name=".GDD01_2"></activity>
  19.   </application>

  20. </manifest>
複製代碼

作者: 李知易    時間: 2019-6-29 10:55

  1. package com.tqc.gdd01;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.TextView;

  9. public class GDD01 extends Activity
  10. {
  11.   private static final String TAG = "Android_Log";
  12.   private TextView tv;
  13.   private Button b1;
  14.   private Button b2;

  15.   @Override
  16.   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  17.     super.onActivityResult(requestCode, resultCode, data);
  18.     if(requestCode == 1999)
  19.     {
  20.       tv.setText(resultCode + "");
  21.     }
  22.   }

  23.   @Override
  24.   public void onCreate(Bundle savedInstanceState){
  25.     super.onCreate(savedInstanceState);
  26.     setContentView(R.layout.main);

  27.     tv=(TextView) findViewById(R.id.text1);;
  28.     b1 = (Button) findViewById(R.id.button1);
  29.     b2 = (Button) findViewById(R.id.button2);

  30.     b1.setOnClickListener(new Button.OnClickListener(){
  31.       public void onClick(View v){
  32.         Intent intent = new Intent(GDD01.this,GDD01_2.class);
  33.         startActivityForResult(intent,1999);
  34.       }
  35.     });

  36.     b2.setOnClickListener(new Button.OnClickListener(){
  37.       public void onClick(View v){
  38.         finish();
  39.       }
  40.     });
  41.     Log.i(TAG, "oncreate()");
  42.   }

  43.   @Override
  44.   public void onStart(){
  45.     super.onStart();
  46.     Log.i(TAG, "onStart()");

  47.   }
  48.   @Override
  49.   public void onResume(){
  50.     super.onResume();
  51.     Log.i(TAG, "onResume()");
  52.   }
  53.   @Override
  54.   public void onPause(){
  55.     super.onPause();
  56.     Log.i(TAG, "onPause()");
  57.   }
  58.   @Override
  59.   public void onStop(){
  60.     super.onStop();
  61.     Log.i(TAG, "onStop()");
  62.   }
  63.   @Override
  64.   public void onRestart(){
  65.     super.onRestart();
  66.     Log.i(TAG, "onRestart()");
  67.   }
  68.   @Override
  69.   public void onDestroy(){
  70.     super.onDestroy();
  71.     Log.i(TAG, "onDestroy()");
  72.   }
  73. }
複製代碼
  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;

  6. /**
  7. * Created by student on 2019/6/15.
  8. */

  9. public class GDD01_2 extends Activity {
  10.     @Override
  11.     protected void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.mylayout);
  14.         Button btn =(Button)findViewById(R.id.button2);
  15.         btn.setOnClickListener(new View.OnClickListener() {
  16.             @Override
  17.             public void onClick(View v) {
  18.                 setResult(99);
  19.                 finish();
  20.             }
  21.         });
  22.     }
  23. }
複製代碼

作者: 張健勳    時間: 2019-6-29 10:56

TQC+ 107
  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.TextView;

  9. public class GDD01 extends Activity
  10. {
  11.   private static final String TAG = "Android_Log";
  12.   private TextView tv;
  13.   private Button b1;
  14.   private Button b2;

  15.   @Override
  16.   public void onCreate(Bundle savedInstanceState){
  17.     super.onCreate(savedInstanceState);
  18.     setContentView(R.layout.main);
  19.     Log.i(TAG, "onCreate");

  20.     tv=(TextView) findViewById(R.id.text1);;
  21.     b1 = (Button) findViewById(R.id.button1);
  22.     b2 = (Button) findViewById(R.id.button2);

  23.     b1.setOnClickListener(new Button.OnClickListener(){
  24.       public void onClick(View v){
  25.         Intent it = new Intent();
  26.         it.setClass(GDD01.this,GDD01_2.class);
  27.         GDD01.this.startActivityForResult(it,0);
  28.       }
  29.     });

  30.     b2.setOnClickListener(new Button.OnClickListener(){
  31.       public void onClick(View v){
  32.         GDD01.this.finish();
  33.       }
  34.     });
  35.   }
  36.   @Override
  37.   public void onActivityResult (int requestCode, int resultCode, Intent data)
  38.   {
  39.     tv.setText(""+resultCode);
  40.   }

  41.   @Override
  42.   public void onStart(){
  43.     super.onStart();
  44.     Log.i(TAG, "onStart");
  45.   }
  46.   @Override
  47.   public void onResume(){
  48.     super.onResume();
  49.     Log.i(TAG, "onResume");
  50.   }
  51.   @Override
  52.   public void onPause(){
  53.     super.onPause();
  54.     Log.i(TAG,"onPause");
  55.   }
  56.   @Override
  57.   public void onStop(){
  58.     super.onStop();
  59.     Log.i(TAG,"onStop");
  60.   }
  61.   @Override
  62.   public void onRestart(){
  63.     super.onRestart();
  64.     Log.i(TAG,"onRestart");
  65.   }
  66.   @Override
  67.   public void onDestroy(){
  68.     super.onDestroy();
  69.     Log.i(TAG,"onDestory");
  70.   }
  71. }
複製代碼
  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.widget.Button;

  7. import com.tqc.gdd01.R;

  8. public class GDD01_2 extends Activity {

  9.     Button btn;

  10.     @Override
  11.     protected void onCreate(Bundle savedInstanceState) {
  12.         // TODO Auto-generated method stub

  13.         super.onCreate(savedInstanceState);
  14.         this.setContentView(R.layout.mylayout);
  15.         btn = (Button) this.findViewById(R.id.button2);
  16.         btn.setOnClickListener(new OnClickListener() {
  17.             public void onClick(View arg0) {
  18.                 GDD01_2.this.setResult(99, GDD01_2.this.getIntent());
  19.                 GDD01_2.this.finish();
  20.             }
  21.         });
  22.     }
  23. }
複製代碼

作者: 李知易    時間: 2019-6-29 11:16

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.   android:layout_width="fill_parent"
  4.   android:layout_height="fill_parent"
  5.   xmlns:android="http://schemas.android.com/apk/res/android"
  6.   android:orientation="vertical"
  7.     android:background="@color/white"
  8.   >
  9.   <EditText
  10.     android:id="@+id/mAccount"
  11.     android:layout_width="fill_parent"
  12.     android:layout_height="wrap_content"
  13.     android:textSize="18sp"
  14.     android:textColor="@color/black"
  15.       android:hint="@string/str1"
  16.       android:inputType="number"
  17.     />
  18.   <EditText
  19.     android:id="@+id/mPassword"
  20.     android:layout_width="fill_parent"
  21.     android:layout_height="wrap_content"
  22.     android:textSize="18sp"
  23.     android:textColor="@color/black"
  24.       android:hint="@string/str2"
  25.       android:inputType="textPassword"
  26.     />
  27.   <CheckBox
  28.     android:id="@+id/mCheck"
  29.     android:layout_width="wrap_content"
  30.     android:layout_height="wrap_content"
  31.     android:textColor="@color/black"
  32.       android:text="顯示密碼"
  33.     />
  34. </LinearLayout>
複製代碼
  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.text.InputType;
  5. import android.view.accessibility.AccessibilityManager;
  6. import android.widget.CheckBox;
  7. import android.widget.CompoundButton;
  8. import android.widget.EditText;

  9. public class GDD01 extends Activity implements CompoundButton.OnCheckedChangeListener {

  10.   @Override
  11.   public void onCreate(Bundle savedInstanceState)
  12.   {
  13.     super.onCreate(savedInstanceState);
  14.     setContentView(R.layout.main);
  15.     CheckBox mcheck = (CheckBox)findViewById(R.id.mCheck);
  16.     mcheck.setOnCheckedChangeListener(this);
  17.   }

  18.   @Override
  19.   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  20.     EditText pw = (EditText)findViewById(R.id.mPassword);
  21.     if(isChecked)
  22.     {
  23.       pw.setInputType(InputType.TYPE_CLASS_TEXT);
  24.     }else
  25.     {
  26.       pw.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
  27.     }
  28.   }
  29. }
複製代碼

作者: 黃璽安    時間: 2019-6-29 11:16

  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.content.DialogInterface;
  4. import android.os.Bundle;
  5. import android.text.InputType;
  6. import android.widget.CheckBox;
  7. import android.widget.CompoundButton;
  8. import android.widget.EditText;

  9. public class GDD01 extends Activity implements CompoundButton.OnCheckedChangeListener {
  10.   @Override
  11.   public void onCreate(Bundle savedInstanceState) {
  12.     super.onCreate(savedInstanceState);
  13.     setContentView(R.layout.main);
  14.     CheckBox mCheck = (CheckBox) findViewById(R.id.mCheck);
  15.     mCheck.setOnCheckedChangeListener(this);

  16.   }

  17.   @Override
  18.   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  19.     EditText pw = (EditText) findViewById(R.id.mPassword);
  20.     if(isChecked){
  21.       pw.setInputType(InputType.TYPE_CLASS_TEXT);
  22.     }else{
  23.       pw.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  24.     }
  25.   }
  26. }
複製代碼
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.   android:layout_width="fill_parent"
  4.   android:layout_height="fill_parent"
  5.   xmlns:android="http://schemas.android.com/apk/res/android"
  6.   android:orientation="vertical"
  7.   android:background="@color/white"
  8.   >
  9.   <EditText
  10.     android:id="@+id/mAccount"
  11.     android:layout_width="fill_parent"
  12.     android:layout_height="wrap_content"
  13.     android:textSize="18sp"
  14.     android:textColor="@color/black"
  15.     android:hint="@string/str1"
  16.     />
  17.   <EditText
  18.     android:id="@+id/mPassword"
  19.     android:layout_width="fill_parent"
  20.     android:layout_height="wrap_content"
  21.     android:textSize="18sp"
  22.     android:textColor="@color/black"
  23.     android:hint="@string/str2"
  24.     />
  25.   <CheckBox
  26.     android:id="@+id/mCheck"
  27.     android:layout_width="wrap_content"
  28.     android:layout_height="wrap_content"
  29.     android:textColor="@color/black"
  30.     android:hint="@string/str3"
  31.     />
  32. </LinearLayout>
複製代碼

作者: 張健勳    時間: 2019-6-29 11:27

  1. package com.tqc.gdd01;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.text.InputType;
  5. import android.widget.CheckBox;
  6. import android.widget.CompoundButton;
  7. import android.widget.EditText;


  8. public class GDD01 extends Activity {
  9.   private EditText edittext;
  10.   private CheckBox checkbox;

  11.   @Override
  12.   public void onCreate(Bundle savedInstanceState)
  13.   {
  14.     super.onCreate(savedInstanceState);
  15.     setContentView(R.layout.main);

  16.     checkbox = (CheckBox) findViewById(R.id.mCheck);

  17.     checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

  18.       @Override
  19.       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  20.         // TODO Auto-generated method stub

  21.         edittext = (EditText) findViewById(R.id.mPassword);

  22.         if (checkbox.isChecked()) {
  23.           edittext.setInputType(InputType.TYPE_CLASS_TEXT);
  24.         } else {
  25.           edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  26.         }

  27.       }
  28.     });
  29.   }
  30. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2