作业7
package com.example.qqq; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import android.widget.TextView; import android.text.Editable; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button=(Button)findViewById(R.id.button1); button.setText("登录"); button.setOnClickListener(new MyButtonListener()); } public class MyButtonListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent=new Intent(); intent.setClass(MainActivity.this,SecondActivity.class); MainActivity.this.startActivity(intent); } } public void CCC(View view) { switch(view.getId()){ case R.id.button1: EditText editText1=(EditText)findViewById(R.id.editText1); String editText11=editText1.getText().toString(); EditText editText2=(EditText)findViewById(R.id.editText2); String editText22=editText2.getText().toString(); String s1="123456"; String s2="asd123"; if(editText11.equals("123456")&&editText22.contentEquals("asd123")) { Toast.makeText(MainActivity.this, "登陆成功",0).show(); } else { Toast.makeText(MainActivity.this, "登陆失败",0).show(); } } } private Object getText(String string) { return null; } private static boolean editText1(String str1) { return false; } public boolean onCreateOptionnsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main,menu); return true; } } <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.qqq.MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="80dp" android:layout_height="80dp" android:layout_alignParentLeft="true" android:layout_marginLeft="90dp" android:src="@drawable/asd" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="80dp" android:onClick="CCC" android:text="登陆" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="20dp" android:layout_marginTop="110dp" android:text="密码" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_below="@+id/textView1" android:layout_marginLeft="20dp" android:layout_marginTop="180dp" android:text="账号" /> <EditText android:id="@+id/editText1" android:layout_width="140dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_below="@+id/textView1" android:layout_marginLeft="80dp" android:layout_marginTop="100dp" android:hint="" /> <EditText android:id="@+id/editText2" android:layout_width="140dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_below="@+id/textView1" android:layout_marginLeft="80dp" android:layout_marginTop="170dp" android:hint="" android:inputType="textPassword" /> </RelativeLayout> package com.example.qqq; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.EditText; import android.widget.Toast; import android.widget.TextView; import android.text.Editable; import android.view.View; import android.view.View.OnClickListener; public class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.secondlayout); } public void CCC(View view) { switch(view.getId()){ case R.id.button1: EditText editText1=(EditText)findViewById(R.id.editText1); String editText11=editText1.getText().toString(); EditText editText2=(EditText)findViewById(R.id.editText2); String editText22=editText2.getText().toString(); String s1="123456"; String s2="asd123"; if(editText11.equals("123456")&&editText22.contentEquals("asd123")) { Toast.makeText(SecondActivity.this, "登陆成功",0).show(); } else { Toast.makeText(SecondActivity.this, "登陆失败",0).show(); } } } private Object getText(String string) { return null; } private static boolean editText1(String str1) { return false; } public boolean onCreateOptionnsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main,menu); return true; } } <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imageView1" android:layout_width="80dp" android:layout_height="80dp" android:layout_alignParentLeft="true" android:layout_marginLeft="90dp" android:src="@drawable/asd" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="80dp" android:onClick="CCC" android:text="登陆" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="20dp" android:layout_marginTop="110dp" android:text="密码" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_below="@+id/textView1" android:layout_marginLeft="20dp" android:layout_marginTop="180dp" android:text="账号" /> <EditText android:id="@+id/editText1" android:layout_width="140dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_below="@+id/textView1" android:layout_marginLeft="80dp" android:layout_marginTop="100dp" android:hint="" /> <EditText android:id="@+id/editText2" android:layout_width="140dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_below="@+id/textView1" android:layout_marginLeft="80dp" android:layout_marginTop="170dp" android:hint="" /> </RelativeLayout> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.qqq" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="22" android:targetSdkVersion="22" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SecondActivity"> </activity> </application> </manifest>