- package com.example.qq;
- import android.support.v7.app.ActionBarActivity;
- import android.text.TextUtils;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends ActionBarActivity {
- private EditText et_qq;
- private EditText et_passWord;
- private CheckBox cb_remember;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- et_qq = (EditText) findViewById(R.id.et_qq);
- et_passWord = (EditText) findViewById(R.id.et_passWord);
- cb_remember = (CheckBox) findViewById(R.id.cb_remeber);
-
- }
- public void login(View view){
- String qq = et_qq.getText().toString().trim();
- String password = et_passWord.getText().toString().trim();
- if(TextUtils.isEmpty(qq)||TextUtils.isEmpty(password)){
- Toast.makeText(this, "用户名和密码不能为空", 0).show();
- return;
- }else{
- if("10000".equals(qq)&&"123456".equals(password)){
- Toast.makeText(this, "登陆成功", 0).show();
- }else{
- Toast.makeText(this, "登陆失败", 0).show();
- }
- }
-
- }
- }
复制代码
跟着老师的写怎么最后却点登陆按钮没什么反应
下面是xml- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center_horizontal"
- android:orientation="vertical" >
- <EditText
- android:id="@+id/et_qq"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="请输入QQ号" >
- <requestFocus />
- </EditText>
- <EditText
- android:id="@+id/et_passWord"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="请输入密码"
- android:inputType="textPassword" />
- <CheckBox
- android:id="@+id/cb_remeber"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="记住用户名和密码" />
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="登录" />
- </LinearLayout>
复制代码 |
|