首页 > 代码库 > Code Review(自评)

Code Review(自评)

<?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:orientation="vertical">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录界面"
        android:textSize="30dp"
        android:background="#DBDBDB"
        android:layout_gravity="center"></TextView>

    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入用户名"/>

    <EditText
        android:id="@+id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:password="true"
        android:hint="请输入密码"/>
    <Button
        android:id="@+id/bt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录"
        android:layout_gravity="center"
        />


</LinearLayout>
package com.example.app3;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button bt1 = (Button)findViewById(R.id.bt1);
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent(MainActivity.this,Second.class);
                startActivity(myIntent);
            }
        });

    }
    protected  void dialog(){
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("提示");
        builder.setIcon(R.mipmap.ic_launcher);
        builder.setMessage("退出?");
        builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                MainActivity.this.finish();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if(keyCode==event.KEYCODE_BACK){
            dialog();
        }
        return super.onKeyDown(keyCode, event);
    }
}
<?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>
package com.example.app3;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;


/**
 * Created by Mr.Wu on 2016/9/27.
 */
public class Second extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);
}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
            menu.add(Menu.NONE,1,1,"个人信息保护");
            menu.add(Menu.NONE,2,2,"设置");
            menu.add(Menu.NONE,3,3,"问卷调查");
            menu.add(Menu.NONE,4,4,"关于");
            menu.add(Menu.NONE,5,5,"帮助");
            return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case 1:
                Toast.makeText(Second.this,"你点击了个人信息保护",Toast.LENGTH_SHORT).show();
                break;
            case 2:
                Toast.makeText(Second.this,"你点击了设置",Toast.LENGTH_SHORT).show();
                break;
            case 3:
                Toast.makeText(Second.this,"你点击了问卷调查",Toast.LENGTH_SHORT).show();
                break;
            case 4:
                Toast.makeText(Second.this,"你点击了关于",Toast.LENGTH_SHORT).show();
                break;
            case 5:
                Toast.makeText(Second.this,"你点击了帮助",Toast.LENGTH_SHORT).show();
                break;

        }
        return super.onOptionsItemSelected(item);
    }

自评:
1.代码中没有注释,条例不够清晰
2.代码的命名不够规范,他人可能无法理解其含义
3.代码能够运行,但没有完成预期的功能
4.UI控件成员变量没有统一加上控件缩写作为后缀

 

Code Review(自评)