Last active
April 17, 2017 20:21
-
-
Save JulioCesarSF/009eb0da84b4b4d6cf6f350db19a4139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity implements View.OnClickListener { | |
private Button btnLogar, btnCadastrar; | |
private EditText edtLogin, edtSenha; | |
private DbHelper dbhelper; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main_activity); | |
initViews(); | |
initDbHelper(); | |
} | |
public void initDbHelper(){ | |
dbhelper = new DbHelper(getApplicationContext()); | |
} | |
public void initViews(){ | |
btnCadastrar = (Button)findViewById(R.id.btnCadastrar); | |
btnCadastrar.setOnClickListener(this); | |
btnLogar = (Button)findViewById(R.id.btnLogar); | |
btnLogar.setOnClickListener(this); | |
edtLogin = (EditText)findVviewById(R.id.edtLogin); | |
edtSenha = (EditText)findVviewById(R.id.edtSenha); | |
} | |
@Override | |
public void onClick(View v) { | |
switch (v.getId()) { | |
case R.id.btnLogar: | |
try{ | |
if(dbhelper.entrar(edtLogin.getText().toString(), edtSenha.getText().toString())) | |
alert("Entrou!"); | |
else | |
alert("Usuário não encontrado!"); | |
}catch(Exception e){ | |
alert(e.getMessage()); | |
} | |
break; | |
case R.id.btnCadastrar: | |
//Ir para tela de cadastro CadastroActivity | |
break; | |
} | |
} | |
private void alert(String s) { | |
Toast.makeText(this, s, Toast.LENGTH_LONG).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment