Android Studio密码确认的判断

//PassChangeActivity.java

package com.ppyc.test.Activity;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.ppyc.test.R;
import com.ppyc.test.util.ToastUtil;
import com.zcolin.gui.ZEditTextWithClear;
import com.zcolin.gui.ZEditTextWithPassword;

public class PassChangeActivity extends AppCompatActivity {

    private ZEditTextWithClear ZEditName;
    private ZEditTextWithClear ZEditName1;
    private ZEditTextWithPassword ZEditPass;
    private Button btnOk;
    private Context context;
    private Activity activity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pass_change);
        context=this;
        activity=this;
        findView();
    }

    private void findView() {
        ZEditName=findViewById(R.id.z_edit_name);
        ZEditName1=findViewById(R.id.z_edit_name1);
        ZEditPass=findViewById(R.id.z_edit_pass);
        btnOk=findViewById(R.id.btn_ok);
        btnOk.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(ZEditName.getText().toString())){
                    ToastUtil.ShortToast(context, "旧密码不能为空");
                }else{
                    if(!TextUtils.isEmpty(ZEditName1.getText().toString()) && TextUtils.equals(ZEditName1.getText().toString(),ZEditPass.getText().toString())){
                        ToastUtil.ShortToast(context,"修改成功");
                    }else{
                        ToastUtil.ShortToast(context,"两次密码不相同或新密码为空");
                    }
                }
            }
        });
    }
}

//FourFragment.java

package com.ppyc.test.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.ppyc.test.Activity.AboveOursActivity;
import com.ppyc.test.Activity.LoginActivity;
import com.ppyc.test.Activity.PassChangeActivity;
import com.ppyc.test.Activity.TaskActivity;
import com.ppyc.test.Activity.TaskActivity1;
import com.ppyc.test.Activity.UserInfoActivity;
import com.ppyc.test.R;
import com.ppyc.test.util.IntentUtil;
import com.ppyc.test.util.ToastUtil;
import com.zcolin.gui.ZKeyValueView;

public class FourFragment extends Fragment implements View.OnClickListener{
    private View view;
    private ZKeyValueView zKVMy,zKVTask,zKVPass,zKVMe;
    private Button btnLogin;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //加载fragment的xml
        view=inflater.inflate(R.layout.fragment_four,null);
        findView();
        return view;
    }
    //控件的绑定
    private void findView() {
        zKVMy = view.findViewById(R.id.z_kv_my);
        zKVTask = view.findViewById(R.id.z_kv_task);
        zKVPass = view.findViewById(R.id.z_kv_pass);
        zKVMe = view.findViewById(R.id.z_kv_me);
        btnLogin = view.findViewById(R.id.btn_login);
        //点击事件声明
        zKVMy.setOnClickListener(this);
        zKVTask.setOnClickListener(this);
        zKVPass.setOnClickListener(this);
        zKVMe.setOnClickListener(this);
        btnLogin.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.z_kv_my:
                ToastUtil.ShortToast(getContext(),"个人设置");
                IntentUtil.setIntent(getContext(), UserInfoActivity.class);
                break;
            case R.id.z_kv_task:
//                ToastUtil.ShortToast(getContext(),"任务管理");
                IntentUtil.setIntent(getContext(), TaskActivity1.class);
                break;
            case R.id.z_kv_pass:
                ToastUtil.ShortToast(getContext(),"密码修改");
                IntentUtil.setIntent(getContext(), PassChangeActivity.class);
                break;
            case R.id.z_kv_me:
                ToastUtil.ShortToast(getContext(),"关于我们");
                IntentUtil.setIntent(getContext(), AboveOursActivity.class);
                break;
            case R.id.btn_login:
                IntentUtil.setIntent(getActivity(), LoginActivity.class);
                break;
        }
    }
}

activity_pass_change.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activity.LoginActivity"
    >
    <com.zcolin.gui.ZEditTextWithClear
        android:id="@+id/z_edit_name1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_above="@+id/z_edit_pass"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:paddingLeft="5dp"
        android:hint="键入新密码"
        android:background="@drawable/edit_login"
        />
    <com.zcolin.gui.ZEditTextWithClear
        android:id="@+id/z_edit_name"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_above="@+id/z_edit_pass"
        android:layout_marginBottom="80dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:paddingLeft="5dp"
        android:hint="键入旧密码"
        android:background="@drawable/edit_login"
        />
    <com.zcolin.gui.ZEditTextWithPassword
        android:id="@+id/z_edit_pass"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:hint="请确认密码"
        android:paddingLeft="5dp"
        android:background="@drawable/edit_login"
        />
    <Button
        android:id="@+id/btn_ok"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/z_edit_pass"
        android:layout_marginTop="50dp"
        android:text="确认修改"
        android:textSize="18dp"

        />

</RelativeLayout>


 


 

猜你喜欢

转载自blog.csdn.net/Percy0618/article/details/82023749