demo05
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:id="@+id/msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="please input userpassword:" /> <EditText android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="false" android:text="show Password" /> <TextView android:id="@+id/xinbei" android:text="你的性别是:" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="20px"/> </LinearLayout> =========================== package com.example.chapter06passwordrediogroup; import android.os.Bundle; import android.app.Activity; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; import android.view.Menu; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; public class MainActivity extends Activity { private EditText password=null; private CheckBox show =null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.password= (EditText)super.findViewById(R.id.password); this.show = (CheckBox)super.findViewById(R.id.show); this.show.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (show.isChecked()){ MainActivity.this.password.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); }else{ MainActivity.this.password.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }