Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bg.ittalents.lesson35;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.Toast;
- import java.util.ArrayList;
- import bg.ittalents.lesson35.model.User;
- public class Main extends AppCompatActivity {
- private static ArrayList<User> users = new ArrayList<>();
- static {
- users.add(new User("Rado","123", false));
- users.add(new User("Didi","123", true));
- users.add(new User("Niki","123" , false));
- }
- private EditText userName;
- private EditText pass;
- private CheckBox isAdminBox;
- private Button buton;
- private User userLogged;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- userName = (EditText)findViewById(R.id.user_name);
- pass = (EditText)findViewById(R.id.pass);
- isAdminBox = (CheckBox)findViewById(R.id.chekche);
- buton = (Button)findViewById(R.id.login_button);
- buton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String nameText = userName.getText().toString();
- String passText = pass.getText().toString();
- boolean isCheck = isAdminBox.isChecked();
- for (User userche : users){
- if(userche.getName().equals(nameText)
- && userche.getPass().equals(passText)
- && (userche.getIsAdmin() == isCheck)){
- userLogged = userche;
- break;
- }
- }
- if(userLogged != null){
- Toast.makeText(Main.this, "Zdrasti " + userLogged.getName(), Toast.LENGTH_SHORT).show();
- Intent intent = new Intent(Main.this, Exam.class);
- startActivity(intent);
- finish();
- }else{
- Toast.makeText(Main.this, "Gledai si rabotata ! " + nameText, Toast.LENGTH_SHORT).show();
- }
- userLogged = null;
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment