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

TOP

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

TOP

返回列表