CERCA
PER MODELLO
FullScreen Chatbox! :)

Utente del giorno: gianpassa con ben 1 Thanks ricevuti nelle ultime 24 ore
Utente della settimana: carotix con ben 11 Thanks ricevuti negli ultimi sette giorni
Utente del mese: megthebest con ben 26 Thanks ricevuti nell'ultimo mese

Visualizzazione dei risultati da 1 a 1 su 1
Discussione:

activity signup e controlli DB

Se questa discussione ti è stata utile, ti preghiamo di lasciare un messaggio di feedback in modo che possa essere preziosa in futuro anche per altri utenti come te!
  1. #1
    Androidiano L'avatar di Chry1911


    Registrato dal
    Oct 2012
    Località
    Varese
    Messaggi
    100
    Smartphone
    Samsung galaxy note II

    Ringraziamenti
    0
    Ringraziato 1 volta in 1 Post
    Predefinito

    activity signup e controlli DB

    Salve amici sto sviluppando un'app

    ho problemi su database nel senso che riesco a registrare un utente al servizio ma non riesco a fare il controllo per vedere se esso è già registrato....ecco qui le due classi che sto usando per farlo:

    codice:
    /**
     * Created by christian on 27/01/2016.
     */
    public class MySQLiteHelper extends SQLiteOpenHelper {
        //database version
        private static final int DATABASE_VERSION = 1;
        //database name
        private static final String DATABASE_NAME = "ToDoNotes";
    
        public MySQLiteHelper(Context context){
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    
        @Override
        /**
         * Metodo per creare la tabella ToDoNotes_Users
         */
    
        public void onCreate(SQLiteDatabase db){
            String CREATE_TODONOTES_USERS = "CREATE TABLE ToDoNotes_Users (" +
                    "name TEXT, "+
                    "email TEXT PRIMARY KEY, "+
                    "password TEXT)" ;
    
    
            db.execSQL(CREATE_TODONOTES_USERS);
        }
    
        @Override
        /**
         * Il metodo OnUpgrade elimina la tabella se già presente per crearne una nuova
         */
    
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
            db.execSQL("DROP TABLE IF EXISTS ToDoNotes_Users");
            this.onCreate(db);
        }
        //Tabella Utenti
        public static final String TABLE_USERS = "ToDoNotes_Users";
    
        // Colonne tabella utenti
        private static final String name = "name";
        private static final String email = "email";
        private static final String password = "password";
        //private static final String code ="captcha";
    
    
        /**
         * Il metodo inserisce gli utenti nella tabella del database
         */
        public void addUser(User u){
        Log.d("Utenti", u.toString());
    
            SQLiteDatabase db = this.getWritableDatabase();
    
            ContentValues values = new ContentValues();
            values.put(name, u.getName());
            values.put(email, u.getEmail());
            values.put(password, u.getPassword());
    
            db.insert(TABLE_USERS, null, values);
    
            db.close();
        }
    
        public User ExistingUser(String mail){
            // metodo per vedere se un utente è già registrato
            Log.d("Verifica", email);
    
            SQLiteDatabase db = this.getReadableDatabase();
            //String sql = "SELECT email from ToDoNotes_Users Where email=?";
            Cursor cursor = db.query(TABLE_USERS, new String[]{name,email,password}, "email = ?", new String[]{mail}, null, null, null, null);
            if(cursor != null)
                cursor.moveToFirst();
    
            User user = new User();
            user.setName(cursor.getString(0));
            user.setEmail(cursor.getString(1));
            user.setPassword(cursor.getColumnName(2));
    
            Log.d("verifica", user.toString());
            return user;
    
        }
    }

    codice:
    public class SignupActivity extends AppCompatActivity {
        private static final String TAG = "SignupActivity";
    
        public User u;
        public String nome, mail, password,conferma;
        EditText email;
        EditText pass;
        EditText name;
        Button button1;
        TextView text1;
        EditText confirm;
    
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_signup);
            //ButterKnife.bind(this);
    
            final MySQLiteHelper db = new MySQLiteHelper(this);
    
    
            button1 = (Button) findViewById(R.id.btn_signup);
            text1 = (TextView) findViewById(R.id.link_login);
            email = (EditText) findViewById(R.id.input_email);
            pass = (EditText) findViewById(R.id.input_password);
            name = (EditText) findViewById(R.id.input_name);
            confirm = (EditText)findViewById(R.id.conf_password);
    
    
    
            button1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    nome = name.getText().toString();
                    mail = email.getText().toString();
                    password = pass.getText().toString();
                    conferma = confirm.getText().toString();
    
                    if (nome.equals("") || password.equals("") || conferma.equals("") || mail.equals("")) {
                        //Toast.makeText(getApplicationContext(), "Campo mancante, reinserire", Toast.LENGTH_LONG).show();
                        final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
                        progressDialog.setIndeterminate(true);
                        progressDialog.setMessage("Campo mancante, Reinserire..");
                        progressDialog.show();
                        return;
                    }
    
                    if (!password.equals(conferma)) {
                        //Toast.makeText(getApplicationContext(), "Le password non coincidono", Toast.LENGTH_LONG).show();
                        final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
                        progressDialog.setIndeterminate(true);
                        progressDialog.setMessage("Le password non coincidono, reinserire..");
                        progressDialog.show();
                        return;
                    }
    
    
    
    
    
                    else {
                        /*
                            db.ExistingUser(mail);
                            final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
                            progressDialog.setIndeterminate(true);
                            progressDialog.setMessage("Email già in uso..");
                            progressDialog.show();
    */
                            // Save the Data in Database
                            db.addUser(new User(nome, mail, password));
                            //Toast.makeText(getApplicationContext(), "Account Creato Correttamente ", Toast.LENGTH_LONG).show();
                            final ProgressDialog progressDialog2 = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
                            progressDialog2.setIndeterminate(true);
                            progressDialog2.setMessage("Registrazione Effettuata..");
                            progressDialog2.show();
    
                    }
                Intent intentLogin = new Intent(getApplicationContext(), LoginActivity.class);
    
                startActivity(intentLogin);
                // Register(context);
            }
            });
    
            text1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Finish the registration screen and return to the Login activity
                   // finish();
    
                }
            });
    
    
        }
    
        @Override
        protected void onDestroy() {
            // TODO Auto-generated method stub
            super.onDestroy();
    
    
        }
    
    }

    poi un'altra domanda....SendEmail che è una libreria java è supportata su android studio??
    e poi come si crea un'altra tabella sqlite che usa la mia primary key come foreign key in un'altra tabella che mi servirà per le attivazioni della licenza mandate via mail??

  2.  

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire risposte
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Torna su
Privacy Policy