本文实现设置密码对话框的逻辑判断
本文地址:http://www.cnblogs.com/wuyudong/p/5940551.html,转载请注明出处。
首先添加上图按钮的监听事件代码
/** * 设置密码对话框 */ private void showSetPsdDialog() { //需要自己去定义对话框的显示样式,所以要调用dialog.setView(view); Builder builder = new Builder(this); final AlertDialog dialog = builder.create(); final View view = inflate(this, R.layout.dialog_set_psd, null); //让对话框显示一个自己定义的对话框界面效果 dialog.setView(view); dialog.show(); Button bt_submit = (Button) view.findViewById(R.id.bt_submit); Button bt_cancel = (Button) view.findViewById(R.id.bt_cancel); bt_submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText et_set_psd = (EditText) view.findViewById(R.id.et_set_psd); EditText et_confirm_psd = (EditText) view.findViewById(R.id.et_confirm_psd); String psd = et_set_psd.getText().toString(); String confirmPsd = et_confirm_psd.getText().toString(); if(!TextUtils.isEmpty(psd) && !TextUtils.isEmpty(confirmPsd)){ //进入用户手机防盗模块 if(psd.equals(confirmPsd)) { Intent intent = new Intent(getApplicationContext(), testActivity.class); startActivity(intent); //跳转到新的界面以后需要去隐藏对话框 dialog.dismiss(); } else { ToastUtil.show(getApplicationContext(),"密码不一致"); } }else{ //提示用户密码输入为空的情况 ToastUtil.show(getApplicationContext(),"请输入密码"); } } }); bt_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); }
这里新建一个activity:testActivity用来测试,先看到效果,具体后面再实现
public class testActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textView = new TextView(this); textView.setText("testActivity!"); setContentView(textView); } }
然后在清单文件中添加下面的代码:
<activity android:name="com.wuyudong.mobilesafe.activity.testActivity"></activity>