80,337
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.error.MainActivity" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"/>
<EditText
android:id="@+id/edit_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/inputyourname"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password"/>
<EditText
android:id="@+id/edit_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/inputyourpassword"
android:inputType="textPassword"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/mingwen"/>
</LinearLayout>
package com.example.error;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button button=null;
private CheckBox checkBox=null;
private EditText editText=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.button= (Button) findViewById(R.id.button);
this.editText= (EditText) findViewById(R.id.edit_password);
this.button.setOnClickListener(new OnClickListenerImpr());
}
private class OnClickListenerI implements View.OnClickListener{
@Override
public void onClick(View v) {
if(checkBox.isChecked()){
MainActivity.this.editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
MainActivity.this.editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
}
public class OnClickListenerImpr implements View.OnClickListener{
@Override
public void onClick(View v) {
LayoutInflater factory=LayoutInflater.from(MainActivity.this);
View myView=factory.inflate(R.layout.login,null);
checkBox= (CheckBox)myView.findViewById(R.id.checkBox);
Dialog dialog=new AlertDialog.Builder(MainActivity.this)
.setTitle("用户注册")
.setIcon(R.drawable.abc_ab_transparent_dark_holo)
.setPositiveButton("确定",new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "可惜哎还没有连接数据库", Toast.LENGTH_SHORT).show();
}
})
.setView(myView)
.setNegativeButton("取消",new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "hide this view", Toast.LENGTH_SHORT).show();
}
}).create();
dialog.show();
checkBox.setOnClickListener(new OnClickListenerI());
}
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
this.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
editText1.setText(buttonView.getText()+"选中");
}else{
editText1.setText(buttonView.getText()+"取消选中");
}
}
});
这个肯定有啊。。 private Button button;
private CheckBox checkBox;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= (Button) findViewById(R.id.button);
checkBox= (CheckBox) findViewById(R.id.checkBox);
editText= (EditText) findViewById(R.id.edit_password);
button.setOnClickListener(new OnClickListenerImpr());
checkBox.setOnClickListener(new OnClickListenerI());
}