Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In the database class you need to create a method to access the database, eg.</p> <pre><code>public boolean validateUser(String username, String password){ Cursor c = getReadableDatabase().rawQuery( "SELECT * FROM " + TABLE_NAME + " WHERE " + USER_NAME + "='" + username +"'AND "+PASSWORD+"='"+password+"'" , null); if (c.getCount&gt;0) return true; return false; } </code></pre> <p>You will of course need to create the database table with something like</p> <pre><code>public void createTable(SQLiteDatabase database) { String creationString = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ( _id INTEGER PRIMARY KEY AUTOINCREMENT, " + USER_NAME + " TEXT NOT NULL, " + PASSWORD + " TEXT NOT NULL, " ");"; database.execSQL(creationString); } </code></pre> <p>And have variables such as TABLE_NAME which is obviously the name you want to give to the table, USER_NAME which represents the name for the username column, and the same for PASSWORD.</p> <p>You need to call that createTable() method in the onCreate of the database.</p> <p>To use the database with your login button you can do:</p> <pre><code>if (myDatabase.vaidateUser(user_name,pass_word)) { Intent goToNextActivity = new Intent(getApplicationContext(), menu.class); startActivity(goToNextActivity); } else Toast.makeText(mContext, "Wrong username/password", Toast.LENGTH_LONG).show(); </code></pre> <p>Hope this helps. I have given you a good starting block. Theres some other stuff you will need to work out yourself, but this should give you a good idea of how it works and where to go next (like adding the records to the database etc). You will need to create a few variables etc, but that isn't difficult!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload