第一次迭代的感想

时间:2022-03-17 07:09:18

分配任务看了一下,是注册任务的实现功能,这个任务对于开发软件来说都是基础,但还是需要程序大量编辑实现。需要跳转等功能。我看了设计XML的实现,界面如下:第一次迭代的感想

 

 

 

界面设计很简洁明了,代码实现主要就是注册后的跳转代码如下:

........

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.drm.DrmStore;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.edg.foodie.R;
import com.edg.foodie.dao.DatabaseHelper;

public class RegistActivity extends AppCompatActivity {

EditText username;
EditText passwd;
EditText confim;
EditText phone;
CheckBox check;
boolean validation;
private Button dJzhuceBtn;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_regist);

username = (EditText) findViewById(R.id.username);
passwd = (EditText) findViewById(R.id.passwd);
confim = (EditText) findViewById(R.id.passwdconfim);
phone = (EditText) findViewById(R.id.phone);
check = (CheckBox) findViewById(R.id.checkbox);
dJzhuceBtn = (Button)findViewById(R.id.DJzhuceBtn);
dJzhuceBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
Toast.makeText(RegistActivity.this,"恭喜您注册成功",Toast.LENGTH_LONG).show();
}
});


findViewById(R.id.backbtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(RegistActivity.this, LoginActivity.class));
}
});

findViewById(R.id.resetbtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username.setText("");
passwd.setText("");
confim.setText("");
phone.setText("");
check.setChecked(false);
}
});

//检测账户是否为8位
username.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {

if (!hasFocus) {
if (username.getText().toString().length() < 8) {
Toast.makeText(RegistActivity.this, "账号至少8位有效字符", Toast.LENGTH_SHORT).show();
}
}
}
});

//密码检测
passwd.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus)
{
if( passwd.getText().toString().length() < 6)
{
Toast.makeText(RegistActivity.this, "密码至少为6位有效字符", Toast.LENGTH_SHORT).show();
}
}
}
});

//两次密码对比
confim.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus)
{
if(!confim.getText().toString().trim().equals(passwd.getText().toString().trim()))
{
Toast.makeText(RegistActivity.this, "两次输入密码不一致", Toast.LENGTH_SHORT).show();
}
}
}
});

phone.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus)
{
if (phone.getText().toString().trim().length()!=11)
{
Toast.makeText(RegistActivity.this, "手机格式不正确", Toast.LENGTH_SHORT).show();
}
}
}
});

findViewById(R.id.DJzhuceBtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = getIntent();

//判断账户密码
if (TextUtils.isEmpty(username.getText().toString())||
TextUtils.isEmpty(passwd.getText().toString()))
{
Toast.makeText(RegistActivity.this, "用户名或密码不能为空", Toast.LENGTH_SHORT).show();
return;
}
else if (username.getText().toString().trim().length()<8||
passwd.getText().toString().trim().length()<6)
{
Toast.makeText(RegistActivity.this, "用户名或密码格式不正确", Toast.LENGTH_SHORT).show();
return;
}

if(!confim.getText().toString().trim().equals(passwd.getText().toString().trim()))
{
Toast.makeText(RegistActivity.this, "两次输入密码不一致", Toast.LENGTH_SHORT).show();
return;
}

//判断手机号码
if (TextUtils.isEmpty(phone.getText().toString()))
{
Toast.makeText(RegistActivity.this, "请输入手机号码", Toast.LENGTH_SHORT).show();
return;
}else if (phone.getText().toString().trim().length()!=11)
{
Toast.makeText(RegistActivity.this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show();
return;
}

if (!check.isChecked())
{
Toast.makeText(RegistActivity.this, "对不起,您未接受用户使用协议。我们无法为您提供服务", Toast.LENGTH_SHORT).show();
return;
}


//{这里写数据库处理}
DatabaseHelper dbHelper = new DatabaseHelper(RegistActivity.this,"user_db");

SQLiteDatabase db = dbHelper.getWritableDatabase();

ContentValues values = new ContentValues();
values.put("username",username.getText().toString());
values.put("passwd",passwd.getText().toString());
values.put("phone",phone.getText().toString());
db.insert("user", null, values);


Bundle data = new Bundle();
data.putString("username", username.getText().toString());
i.putExtras(data);
setResult(1, i);
finish();
Toast.makeText(RegistActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
}
});


}

}

......

第一次迭代的感想

 

在编译过程中其实很多东西都不能一下子延续下去,查阅之前的代码并且和同学合作才把它给完成了,所有的事情经过认真努力一定有相应的成功。