安卓登录注册---view层

Iview接口

package com.xinzhengwei.denglu.view;

/**
 * Created by 辛政维 on 2018/1/12.
 */

public interface Iviwe {

    String getMobile();
    String getPassword();
    void jumpActivity();
    void shouError();

}


MainActivity主页面

package com.xinzhengwei.denglu.view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xinzhengwei.denglu.R;
import com.xinzhengwei.denglu.model.ImodelImp;
import com.xinzhengwei.denglu.presenter.Presenter;
import com.xinzhengwei.denglu.presenter.PresenterImp;

public class MainActivity extends AppCompatActivity implements Iviwe, View.OnClickListener {

    private EditText mobile;
    private EditText password;
    private Button login;
    private Button reg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {

        mobile = findViewById(R.id.mobile);
        password = findViewById(R.id.password);
        login = findViewById(R.id.login);
        reg = findViewById(R.id.reg);
        login.setOnClickListener(this);
        reg.setOnClickListener(this);

    }

    @Override
    public String getMobile() {
        return mobile.getText().toString();
    }

    @Override
    public String getPassword() {
        return password.getText().toString();
    }

    @Override
    public void jumpActivity() {
        startActivity(new Intent(MainActivity.this,ContActivity.class));
    }

    @Override
    public void shouError() {
        Toast.makeText(this, "登录失败,请注册", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()){

            case R.id.login:
                PresenterImp presenterImp = new PresenterImp();
                presenterImp.login(new ImodelImp(),MainActivity.this);
                break;
            case R.id.reg:
                startActivity(new Intent(MainActivity.this,RegActivity.class));
                break;

        }

    }
}

 主页面布局
<?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"
    android:orientation="vertical"
    tools:context="com.xinzhengwei.denglu.view.MainActivity">

   <EditText
       android:id="@+id/mobile"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal">

        <Button
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登录"/>

        <Button
            android:id="@+id/reg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册"/>

    </LinearLayout>

</LinearLayout>

RegActivity注册页面
package com.xinzhengwei.denglu.view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xinzhengwei.denglu.R;
import com.xinzhengwei.denglu.model.ImodelImp;
import com.xinzhengwei.denglu.presenter.PresenterImp;

public class RegActivity extends AppCompatActivity implements Iviwe, View.OnClickListener {

    private EditText mobile;
    private EditText password;
    private Button reg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);
        initView();
    }

    private void initView() {

        mobile = findViewById(R.id.mobile);
        password = findViewById(R.id.password);
        reg = findViewById(R.id.reg);
        reg.setOnClickListener(this);

    }

    @Override
    public String getMobile() {
        return mobile.getText().toString();
    }

    @Override
    public String getPassword() {
        return password.getText().toString();
    }

    @Override
    public void jumpActivity() {
        startActivity(new Intent(RegActivity.this,MainActivity.class));
    }

    @Override
    public void shouError() {
        Toast.makeText(this, "注册失败,请重新注册", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View view) {

        PresenterImp presenterImp = new PresenterImp();
        presenterImp.reg(new ImodelImp(),this);

    }
}

注册页面布局
<?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"
    android:orientation="vertical"
    tools:context="com.xinzhengwei.denglu.view.RegActivity">

    <EditText
        android:id="@+id/mobile"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal">

        <Button
            android:id="@+id/reg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="注册"/>

    </LinearLayout>

</LinearLayout>

跳转页面
package com.xinzhengwei.denglu.view;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.xinzhengwei.denglu.R;

/**
 * Created by 辛政维 on 2018/1/12.
 */

public class ContActivity extends Activity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cont_mian);
    }
}

布局
<?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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录成功"/>

</LinearLayout>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值