2013年9月2日 星期一

[TQC+ Android]動態密碼顯示_110

Android 2.1 API 7 版本原始題目載點:http://db.tt/7DRVeeKb

僑光科技大學 蔡存孝老師 解說參考:http://rs2.ocu.edu.tw/~tsay/files/TQC110.pdf

GDD01.java - Activity主體
package COM.TQC.GDD01;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;


public class GDD01 extends Activity {
 private EditText et;
 private CheckBox cb;
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    et = (EditText) findViewById(R.id.mPassword);
    cb = (CheckBox) findViewById(R.id.mCheck);
    
    cb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){

  @Override
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
   // TODO Auto-generated method stub
   if(cb.isChecked()){
    et.setTransformationMethod(
                  HideReturnsTransformationMethod.getInstance());
   }else{
    et.setTransformationMethod(
                  PasswordTransformationMethod.getInstance());
   }
  }
     
    });
  }
}

沒有留言:

張貼留言