和小伙伴的结伴编程

和徐鹏小伙伴的结对编程

由于我能力比较弱我就写了一个小软件简单的登陆

:)

package com.example.chen;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText mUserName = (EditText) this.findViewById(R.id.editText1);
        final EditText mPassword = (EditText) this.findViewById(R.id.editText2);
        Button mSubmit =  (Button)this.findViewById(R.id.button1);
        final TextView mResult = (TextView)this.findViewById(R.id.textView1);
        mSubmit.setOnClickListener( new OnClickListener() {
            
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                   String userName = mUserName.getText().toString();
                   String password = mPassword.getText().toString();
                   if("hudaochen".equals(userName) && "123".equals(password)){
                       mResult.setText("恭喜您,登录成功!");
                   }else{
                       mResult.setText("登录失败,用户名或密码不正确!");
                   }
                   
       }

   } );
            

    }

    @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);
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout 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.chen.MainActivity" 
    android:orientation="vertical">

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="输入用户名"
        android:ems="10"
        android:text="" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="输入密码"
        android:text=""
        android:ems="10"
        android:inputType="textPassword" />

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="登陆结果"/>

</LinearLayout>

我写一半他写一半遇到不会的他指导我一下

原文地址:https://www.cnblogs.com/hudaochen/p/6637669.html