团队冲刺——第六天
Posted hang-hang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了团队冲刺——第六天相关的知识,希望对你有一定的参考价值。
今天学习了Activity的用法和Activity中使用fragment的方法,然后实战做了一下登陆注册功能。遇到困难在找到控件与保存数据方面不太懂。明天做出来完整登陆注册功能。
今天所写做对的登陆和注册功能:
package com.example.a15979.shudong;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.a15979.shudong.service.UserService;
import com.example.a15979.shudong.R;
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);//即activity_login.xml
findViews();
}
private EditText username;
private EditText password;
private Button login;
private Button register;
private void findViews() {
username=(EditText) findViewById(R.id.username);
password=(EditText) findViewById(R.id.password);
login=(Button) findViewById(R.id.login);
register=(Button) findViewById(R.id.register);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name=username.getText().toString();
System.out.println(name);
String pass=password.getText().toString();
System.out.println(pass);
Log.i("TAG",name+"_"+pass);
UserService uService=new UserService(LoginActivity.this);
boolean flag=uService.login(name, pass);
if(flag){
Log.i("TAG","登录成功");
Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_LONG).show();
Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
startActivity(intent);
}else{
Log.i("TAG","登录失败");
Toast.makeText(LoginActivity.this, "登录失败", Toast.LENGTH_LONG).show();
}
}
});
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(LoginActivity.this,RegisterActivity.class);
startActivity(intent);
}
});
}
}
注册:
package com.example.a15979.shudong;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.example.a15979.shudong.service.UserService;
import com.example.a15979.shudong.R;
public class RegisterActivity extends AppCompatActivity {
EditText username;
EditText password;
EditText age;
RadioGroup sex;
Button register;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
findViews();
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String name=username.getText().toString().trim();
String pass=password.getText().toString().trim();
Log.i("TAG",name+"_"+pass+"_");
UserService uService=new UserService(RegisterActivity.this);
User user=new User();
user.setUsername(name);
user.setPassword(pass);
uService.register(user);
Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_LONG).show();
}
});
}
private void findViews() {
username=(EditText) findViewById(R.id.usernameRegister);
password=(EditText) findViewById(R.id.passwordRegister);
register=(Button) findViewById(R.id.Register);
}
}
以上是关于团队冲刺——第六天的主要内容,如果未能解决你的问题,请参考以下文章