今天实现登录功能
和web差不多
public class register extends AppCompatActivity {
private static String name;
public static String getName() {
return name;
}
public static void setName(String name) {
com.example.mymap.register.name = name;
}
EditText number;
EditText mima;
Button xianshi;
Button register;//登陆按钮
Button login;//注册按钮
List<user> list;
Intent intent = new Intent();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
number = findViewById(R.id.number);
mima = findViewById(R.id.mima);
login = findViewById(R.id.login);
register = findViewById(R.id.register);
web_login web = new web_login();
userlist userlist = new userlist();
Thread thread = new Thread(userlist);
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
list = userlist.getUserlist();//获取的用户数组
//登陆按钮
xianshi = findViewById(R.id.xianshi);
register.setOnClickListener(new View.OnClickListener() {
int i=0;
@Override
public void onClick(View v) {
System.out.println("size"+list.size());//输出长度
for (i=0;i<list.size();i++){//for循环做判断
System.out.println("register"+number.getText().toString()+mima.getText().toString());//输出用户输入的账户与密码
System.out.println(number.getText().toString().equals(list.get(i).getNumber())&&mima.getText().toString().equals(list.get(i).getPhone()));
if(number.getText().toString().equals(list.get(i).getNumber())&&mima.getText().toString().equals(list.get(i).getPhone())){
name = list.get(i).getName();
intent.setClass(register.this,MainActivity.class);
startActivity(intent);
return;
}
}
Toast.makeText(register.this, "用户不存在", Toast.LENGTH_SHORT).show();
}
});
//********
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intent.setClass(register.this, com.example.mymap.login.class);
startActivity(intent);
}
});
xianshi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intent.setClass(register.this,xianshiclass.class);
startActivity(intent);
}
});
}
}