Practical No 26
Practical No 26
Practical No 26
Q1.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="162dp"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Atharva Butte"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<LinearLayout
android:layout_width="414dp"
android:layout_height="657dp"
android:layout_marginTop="36dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Login"
android:textSize="34sp" />
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:src="@drawable/img"/>
<Space
android:layout_width="match_parent"
android:layout_height="70dp" />
<EditText
android:id="@+id/unm"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:inputType="text"
android:text="Enter Name" />
<EditText
android:id="@+id/pass"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="text"
android:text="Enter Password" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="20dp"
android:layout_marginRight="60dp"
android:text="Register Here" android:onClick="submit"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.practical27;
import androidx.appcompat.app.AppCompatActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
SQLDemo db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new SQLDemo(MainActivity.this); }
public void submit(View view) {
async_fun asyncFun = new async_fun();
asyncFun.execute();}
class async_fun extends AsyncTask<Void,Void,String>{
@Override
protected String doInBackground(Void... voids) {
if(db.insertData(((EditText) findViewById(R.id.unm)).getText().toString(),
((EditText) findViewById(R.id.pass)).getText().toString()) == true)
return "Register sucessfully";
else
return "Register Failled"; }
@Override
protected void onPostExecute (String result) {
super.onPostExecute(result);
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG).show();
}
}
}
SQLDemo.java
package com.example.practical27;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.*;
import androidx.annotation.Nullable;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }