samedi 31 octobre 2015

Login user with SQLite Database table in Android

i am new in android programming. i am doing a practical with a simple android signup and signin program but i have a difficalty in login with my inserted data in table please help. here is my my code

databasehelper code:

public void getuser(String user){
        SQLiteDatabase db = this.getReadableDatabase();
        String query = "select user, password from "+ DATABASE_TABLE;
        Cursor cu = db.rawQuery(query, null);
        String a,b;
        b = "not found";
        if(cu.moveToFirst())
        {
            do{
                a = cu.getString(0);
                if(a.equals(user))
                {
                    cu.getString(1);
                    break;
                }

            }
        while(cu.moveToNext()); 
        }

and my SignIn. java file

user = (EditText) findViewById(R.id.tfuser);
        pass = (EditText) findViewById(R.id.tfpassword);
        signin = (Button) findViewById(R.id.btnsignin);
        signup = (Button) findViewById(R.id.btnsignup);

        final String suser = user.getText().toString();
        String spass = pass.getText().toString();
        //button
        signin.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                db.getuser(suser);

                if(what to do here){
                Intent welcome = new Intent(SingIn.this, WelcomePage.class);
                startActivity(welcome);}
                else{}


            }
        });

Aucun commentaire:

Enregistrer un commentaire