##老师发了一个study来让我们纠错维护,整个软件是日程管理系统,分为欢迎界面,登录 注册界面,提醒界面添加日程界面,还有个人中心等。一些主要代码老师让我们把缺失部分去维护。首先我们读一下主要代码##
*WelcomActivity是一个欢迎界面,原始老师给的代码为以下代码*
···········
import com.avos.avoscloud.AVUser; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler; public class WelcomeActivity extends Activity { Handler handler = new Handler(); Runnable runnable = new Runnable() { public void run() {
Intent intent = new Intent(WelcomeActivity.this, LoginActivity.class);
startActivity(intent);
finish(); } }; Runnable runnable1 = new Runnable() { public void run() {
Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(intent);
finish(); } }; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
AVUser currentUser = AVUser.getCurrentUser(); if (currentUser != null) {
// 跳转到首页
handler.postDelayed(runnable1, 2000);
} else {
//缓存用户对象为空时,可打开用户注册界面…
handler.postDelayed(runnable, 2000);
} }
}
···········
##代码看起来没有什么问题,可是运行出现了一个小小的问题就是进入到下个界面是闪跳没有停顿,所以我就发现了在跳转首页时候应该加上一个代码
handler.postDelayed(runnable1, 2000);这样界面运行起来就美观合理些##
##其次注册界面,在运行时候出现输入账号密码都出现不能为空现象,原始代码如下:##
·············
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.SignUpCallback; import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; public class RegistActivity extends Activity {
EditText RegistName;
EditText RegistPwd;
EditText RegistPwd2;
Button Regist;
String RName;
String RPwd;
String RPwd2;
String regist; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_regist);
RegistName = (EditText) findViewById(R.id.RegistName);
RegistPwd = (EditText) findViewById(R.id.RegistPwd);
RegistPwd2 = (EditText) findViewById(R.id.RegistPwd2);
Regist = (Button) findViewById(R.id.Regist); // 修改状态栏颜色,4.4+生效
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus();
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.drawable.iphone);//通知栏所需颜色 Regist.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub RName = RegistName.getText().toString();
RPwd = RegistPwd.getText().toString();
RPwd2 = RegistPwd2.getText().toString(); if (!"".equals(RName) && !"".equals(RPwd) && !"".equals(RPwd2)) { if (!RPwd.equals(RPwd2)) { Toast.makeText(RegistActivity.this, "两次输入的密码不一致", Toast.LENGTH_LONG).show(); } else { AVUser user = new AVUser();// 新建 AVUser 对象实例
user.setUsername(RName);// 设置用户名
user.setPassword(RPwd);// 设置密码
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(AVException e) {
if (e == null) {
// 注册成功
Toast.makeText(RegistActivity.this, "注册成功", Toast.LENGTH_LONG).show();
Handler handler = new Handler();
Runnable runnable = new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub
Intent intent = new Intent(RegistActivity.this, LoginActivity.class);
startActivity(intent);
finish(); }
};
handler.postDelayed(runnable, 2000);
} else {
// 失败的原因可能有多种,常见的是用户名已经存在。
Toast.makeText(RegistActivity.this, "用户名已存在", Toast.LENGTH_LONG).show();
}
}
});
}
} }
}); private void setTranslucentStatus() { Window window = this.getWindow();
// Translucent status bar
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
##在运行输入时候总是提示账户密码不能为空,那么,看上面两次密码输入不一致的语句中只有一个IF语句,else语句被遗漏没有其他情况来让程序判定执行,我再在其相对应的语句加上
else {Toast.makeText(RegistActivity.this, "两次输入的密码一致", Toast.LENGTH_LONG).show();}代码##
##其三在登录出现了同样的错误,所以我又在相对应的地方加上了代码
else
{
Toast.makeText(LoginActivity .this, "两次输入的密码不一致", Toast.LENGTH_LONG).show();
}##
##其次我还发现了一些细节问题,在运行时候相对应的XML文件界面不去显示,例如list_item.xml,list_item1.xml界面,运行时候看不出来相对应的效果。##