EditText总结

3.22 打勾显示输入的密码 --EditText与setTransformationMethod

实现目标:
     <EditText
            android:id="@+id/et"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:phoneNumber="true" 
            android:maxLength="11"/>

实现原理:

为CheckBox添加一个监听器事件;

实现的源码:

package edu.cquptzx.showPassword;

 

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;

 

publicclass ShowPasswordActivityextends Activity {

    private EditTextedittext;

    private CheckBoxcheckbox

    /** Called when the activity is first created. */

    publicvoid onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        /*find the object by IDs .*/

       

        edittext = (EditText) findViewById(R.id.et);

        checkbox = (CheckBox) findViewById(R.id.cb);

       

        /* add a listener to the CheckBox */

        checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()

        {

           publicvoid onCheckedChanged(CompoundButton buttonView,boolean isChecked)

           {

              if(checkbox.isChecked())

              {

                  /* show the password*/

                  edittext.setTransformationMethod(HideReturnsTransformationMethod.getInstance());

              }

              else

              {

                  /* hide the password */

                 edittext.setTransformationMethod(PasswordTransformationMethod.getInstance());   

              }         

           }      

        });

    }

}

相关知识:

 

 

 

 

 

最后实现效果:

 

 

 

EditText 密码显示 隐藏三种方法

  (2013-03-07 18:31:58)
标签: 

第三

 

三种

 

方法

 

密码

 

第二

分类: Android

CheckBox ck_ps=null;

EditText ed_input=null;

...

ck_ps.setOnCheckedChangeListener(new OnCheckedChangeListener() {

   @Override
   public void onCheckedChanged(CompoundButton buttonView,
     boolean isChecked) {
    if (isChecked) {

          //显示密码
     //第一种

        ed_input.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

     //第二种
         ed_input.setTransformationMethod(HideReturnsTransformationMethod
       .getInstance());

     //第三种

        ed_input.setInputType(0x90);

    } else {

           //隐藏密码

    //第一种
     ed_input.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
     //第二种
     ed_input.setTransformationMethod(PasswordTransformationMethod
       .getInstance());

     //第三种
     // ed_input.setInputType(0x81);
    }

   }
  });

0
0
(请您对文章做出评价)
«上一篇: 3.20 今晚到哪儿打牙祭--具有选择功能的对话框
»下一篇: 3.23andorid多语言支持--系统架构
posted @ 2012-08-18 10:58 淅沥枫 阅读( 4711) 评论( 0) 编辑 收藏
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值