码迷,mamicode.com
首页 > 其他好文 > 详细

团队冲刺——第六天

时间:2020-04-22 21:31:54      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:content   you   注册   ttext   boolean   登录   成功   app   support   

今天学习了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);
}

}

团队冲刺——第六天

标签:content   you   注册   ttext   boolean   登录   成功   app   support   

原文地址:https://www.cnblogs.com/hang-hang/p/12756058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!