Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public void entrar (View view){
  2. String user = et1.getText().toString();
  3. String password = et2.getText().toString();
  4.  
  5. if(password.length()== 0 || user.length()== 0) {
  6. Toast error = Toast.makeText(this, R.string.alert1, Toast.LENGTH_LONG);
  7. error.show();
  8. }else {
  9. AdminSQLiteOpenHelper conex = new AdminSQLiteOpenHelper(this,"buscaminasbd", null, 1);
  10. SQLiteDatabase bd = conex.getWritableDatabase();
  11. Cursor fila = bd.rawQuery( //cogemos la fila donde coincide el codigo
  12. "select puntos from usuarios where nombre="+user, null);
  13. if(fila.moveToFirst()){
  14. String puntosj = fila.getString(0);
  15. Intent i = new Intent(this, Main2Activity.class);
  16. i.putExtra("nombre", user);
  17. i.putExtra("puntos", puntosj);
  18. startActivity(i);
  19. }else {
  20. Toast.makeText(this, R.string.alert4, Toast.LENGTH_SHORT).show();
  21. }
  22. bd.close();
  23. }
  24. }
  25.  
  26. public class AdminSQLiteOpenHelper extends SQLiteOpenHelper {
  27.  
  28. public AdminSQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
  29. super(context, name, factory, version);
  30. }
  31.  
  32. @Override
  33. public void onCreate(SQLiteDatabase db){
  34. db.execSQL("create table usuarios(nombre text primary key, pass text, puntos integer)");
  35. }
  36. @Override
  37. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement