第十一、十二周作业

 

 

  

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Demo9Activity"
    android:orientation="vertical">

    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入数据"/>
    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="储存"
        android:onClick="click1"
        />
    <EditText
        android:id="@+id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="读取"
        android:onClick="click2"/>
</LinearLayout>
复制代码

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.dell.text12_2.text12">

    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="账号"
        android:textColor="#000000"
        android:textSize="20sp"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        android:padding="10dp"/>

    <EditText
        android:id="@+id/et_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入用户名"
        android:layout_toRightOf="@id/tv_1"
        android:layout_marginTop="30dp"
        android:padding="10dp"
        android:textSize="20sp"/>

    <TextView
        android:id="@+id/tv_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密码"
        android:textColor="#000000"
        android:textSize="20sp"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        android:layout_below="@id/tv_1"
        android:padding="10dp"/>

    <EditText
        android:id="@+id/et_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入密码"
        android:layout_toRightOf="@id/tv_2"
        android:layout_below="@id/et_1"
        android:layout_marginTop="30dp"
        android:padding="10dp"
        android:textSize="20sp"/>

    <EditText
        android:id="@+id/text1"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        />


    <CheckBox
        android:id="@+id/cb_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="记住密码"
        android:textColor="#000000"
        android:textSize="18sp"
        android:layout_below="@id/tv_2"
        android:padding="5dp"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        />

    <CheckBox
        android:id="@+id/cb_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="自动登录"
        android:textColor="#000000"
        android:textSize="18sp"
        android:layout_below="@id/tv_2"
        android:layout_toRightOf="@id/cb_1"
        android:padding="5dp"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        />

    <Button
        android:id="@+id/btn_1"
        android:layout_width="500dp"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textColor="#000000"
        android:textSize="18sp"
        android:layout_below="@id/text1"
        android:padding="5dp"
        android:layout_marginTop="25dp"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@id/cb_2" />



</RelativeLayout>

  

package com.example.dell.text12_2;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Map;

public class text12 extends ActionBarActivity  implements android.view.View.OnClickListener, CompoundButton.OnCheckedChangeListener {


        private EditText et_account;
        private EditText et_password;
        private Button btn_login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text12);
        initView();
        Map<String,String> userInfo=saveQQ.getUserInfo(this);
        if(userInfo!=null){
            et_account.setText(userInfo.get("account"));
            et_password.setText(userInfo.get("password"));
        }
    }

    private void initView() {
        et_account= (EditText) findViewById(R.id.et_1);
        et_password= (EditText) findViewById(R.id.et_2);
        btn_login= (Button) findViewById(R.id.btn_1);
        btn_login.setOnClickListener(this);
        CheckBox cb1= (CheckBox) findViewById(R.id.cb_1);
        cb1.setOnCheckedChangeListener(this);
        CheckBox cb2= (CheckBox) findViewById(R.id.cb_2);
        cb2.setOnCheckedChangeListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_1:
                String account=et_account.getText().toString().trim();
                String password=et_password.getText().toString();
                if(TextUtils.isEmpty(account)){
                    Toast.makeText(this, "请输入账号", Toast.LENGTH_LONG).show();
                    return;
                }
                if(TextUtils.isEmpty(password)){
                    Toast.makeText(this,"请输入密码",Toast.LENGTH_LONG).show();
                    return;
                }
                Toast.makeText(this,"登录成功",Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        switch (compoundButton.getId()){
            case R.id.cb_1:
                String account=et_account.getText().toString().trim();
                String password=et_password.getText().toString();
                boolean isSaveSuccess=saveQQ.saveUserInfo(this,account,password);
                if(isSaveSuccess&&b){
                    Toast.makeText(this,"保存成功",Toast.LENGTH_LONG).show();
                }else {
                    Toast.makeText(this,"保存失败",Toast.LENGTH_LONG).show();
                    et_account.setText(null);
                    et_password.setText(null);
                }
                break;
            case R.id.cb_2:
                account=et_account.getText().toString().trim();
                password=et_password.getText().toString();
                if(TextUtils.isEmpty(account)){
                    Toast.makeText(this,"请输入账号",Toast.LENGTH_LONG).show();
                    return;
                }
                if(TextUtils.isEmpty(password)){
                    Toast.makeText(this,"请输入密码",Toast.LENGTH_LONG).show();
                    return;
                }
                if(b)
                    Toast.makeText(this,"登录成功",Toast.LENGTH_LONG).show();
                else {
                    Toast.makeText(this,"请登录",Toast.LENGTH_LONG).show();
                }
        }
    }
}

  

posted @ 2021-12-01 17:25  咸鱼大佬  阅读(6)  评论(0编辑  收藏  举报