xml文件
<?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:gravity="center"
android:orientation="vertical" >
tools:context="com.example.dell.demo0401test.Main2Activity"
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号"
android:textSize="18sp" />
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码"
android:textSize="18sp" />
<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout>
<Button
android:id="@+id/btn1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="登录" />
</LinearLayout>
java文件
package com.activity.android;
import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
EditText et1, et2;
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
initView();
btn1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Toast.makeText( MainActivity.this, "登录",Toast.LENGTH_SHORT).show ();
}
});
btn1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String s1 = et1.getText().toString();
String s2 = et2.getText().toString();
if (s1.equals("bizideal")&&s2.equals("123456")){
Toast.makeText( MainActivity.this, "登录成功",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText( MainActivity.this, "登录失败",Toast.LENGTH_SHORT).show();
}
}
});
}
private void initView() {
et1 = (EditText) findViewById(R.id.edit);
et2 = (EditText) findViewById(R.id.edit);
btn1 = (Button) findViewById(R.id.button1);
}
}