返回列表 發帖
  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>
複製代碼

TOP

  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>
複製代碼

TOP

返回列表