0% found this document useful (0 votes)
3 views3 pages

Practical 23: Activity Main

The document outlines an Android application that includes a login interface with username and password fields, and a button to submit the login request. It features a MainActivity that handles user input and checks credentials against a database using a DBHelper class, which manages user data storage and retrieval. The application includes basic functionality for user authentication and database operations.

Uploaded by

ayushx312
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Practical 23: Activity Main

The document outlines an Android application that includes a login interface with username and password fields, and a button to submit the login request. It features a MainActivity that handles user input and checks credentials against a database using a DBHelper class, which manages user data storage and retrieval. The application includes basic functionality for user authentication and database operations.

Uploaded by

ayushx312
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical 23

Activity main

<!-- activity_login.xml -->


<LinearLayout <EditText
xmlns:android="[Link] android:id="@+id/password"
om/apk/res/android" android:hint="Enter Password"
android:orientation="vertical" android:inputType="textPassword"
android:padding="20dp" android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"/>
android:layout_marginTop="100dp">
<Button
<EditText android:id="@+id/loginBtn"
android:id="@+id/username" android:text="Login"
android:hint="Enter Username" android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"/> </LinearLayout>

MainActivity

package [Link]; savedInstanceState) {


[Link](savedInstanceState);
import [Link];
import [Link]; setContentView([Link].activity_main);
import [Link];
import [Link]; username =
import findViewById([Link]);
[Link] password =
vity; findViewById([Link]);
loginBtn = findViewById([Link]);
public class MainActivity extends
AppCompatActivity { DB = new DBHelper(this);

EditText username, password; // Sample user insert (for testing)


Button loginBtn; [Link]("Ayush", "1234");
DBHelper DB;
[Link](view -> {
@Override String user =
protected void onCreate(Bundle [Link]().toString();
String pass = [Link](this, "Invalid
[Link]().toString(); Credentials",
Toast.LENGTH_SHORT).show();
if ([Link](user, pass)) { }
[Link](this, "Login });
Successful", }
Toast.LENGTH_SHORT).show(); }
} else {

DBHelper

package [Link]; users");


}
import [Link];
import [Link]; public Boolean insertData(String
import [Link]; username, String password) {
import SQLiteDatabase db =
[Link]; [Link]();
import ContentValues values = new
[Link] ContentValues();
er; [Link]("username", username);
[Link]("password", password);
public class DBHelper extends
SQLiteOpenHelper { long result = [Link]("users", null,
values);
public DBHelper(Context context) { return result != -1;
super(context, "[Link]", null, 1); }
}
public Boolean checkUser(String
@Override username, String password) {
public void onCreate(SQLiteDatabase SQLiteDatabase db =
db) { [Link]();
[Link]("CREATE TABLE Cursor cursor = [Link](
users(username TEXT PRIMARY KEY, "SELECT * FROM users WHERE
password TEXT)"); username=? AND password=?",
} new String[]{username, password}
);
@Override return [Link]() > 0;
public void onUpgrade(SQLiteDatabase }
db, int oldVersion, int newVersion) { }
[Link]("DROP TABLE IF EXISTS

You might also like