Follow Below Steps for make simple login applicaiton in Android using database with Dialog demo.
1)DataBaseDemoActivity.java
This file diplay login page and trasfer two edit text data into second activity........
package database.co.in;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class DataBaseDemoActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
EditText mtxt_email, mtxt_password;
Button mLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mtxt_email = (EditText)findViewById(R.id.editEmail_id);
mtxt_password = (EditText)findViewById(R.id.editPassword);
mLogin = (Button)findViewById(R.id.button1);
mLogin.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String email = mtxt_email.getText().toString();
String password = mtxt_password.getText().toString();
System.out.println("Email id:-"+email);
System.out.println("Password:-"+password);
Intent dbintent = new Intent(this.getApplicationContext(),DbEntry.class);
dbintent.putExtra("p_email", email);
dbintent.putExtra("p_password", password);
startActivity(dbintent);
}
}
2)main.xml
This is login page gui.. also this file need one header.xml which include externally.......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/apple1" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textEmail_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="69dp"
android:text="Email ID"
android:textSize="20dp"
android:gravity="center|left"
android:textColor="@android:color/holo_purple" />
<EditText
android:id="@+id/editEmail_id"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="@+id/button1"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/textEmail_id"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/textPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textEmail_id"
android:layout_below="@+id/editEmail_id"
android:text="Password"
android:textSize="20dp"
android:textColor="@android:color/holo_purple" />
<EditText
android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="@+id/editEmail_id"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/textPassword"
android:layout_marginTop="10dp" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editPassword"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:background="@drawable/login" />
<include layout="@layout/header"/>
</RelativeLayout>
</LinearLayout>
3) header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:text="Welcome To @pple"
android:textSize="25dp"
android:textColor="@android:color/holo_purple" />
</LinearLayout>
4) DbEntry.java
Below code for database logic..... and show Dialog in second page check. it
package database.co.in;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.widget.Toast;
public class DbEntry extends Activity {
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
System.out.println("All iz well. ");
Intent getdbintent = getIntent();
String email = getdbintent.getStringExtra("p_email");
String password = getdbintent.getStringExtra("p_password");
db = openOrCreateDatabase("login.db",SQLiteDatabase.CREATE_IF_NECESSARY ,null);
String createTable = "CREATE TABLE IF NOT EXISTS info ("
+ "Emailid TEXT,"
+ "PassWord TEXT);";
db.execSQL(createTable);
String insertData = "INSERT or replace INTO info (Emailid, PassWord) VALUES('"+email+"','"+password+"')" ;
db.execSQL(insertData);
db.close();
System.out.println("All iz well.database has benn insert successfully. ");
Toast.makeText(getApplicationContext(), "welcome to o@k Tech"+email+"Password+"+password, Toast.LENGTH_LONG).show();
showDialog(1);
}
protected Dialog onCreateDialog(int i) {
Dialog dialog = null;
switch (i) {
case 1:
dialog = new Dialog(this);
dialog.setTitle("Welcome to O@k Tech...... ....");
dialog.setContentView(R.layout.dialog);
break;
default:
break;
}
return dialog;
}
}
5) dialog.xml
This file content only one button which is display on dialog box .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thanx to Login........." />
</LinearLayout>
1)DataBaseDemoActivity.java
This file diplay login page and trasfer two edit text data into second activity........
package database.co.in;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class DataBaseDemoActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
EditText mtxt_email, mtxt_password;
Button mLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mtxt_email = (EditText)findViewById(R.id.editEmail_id);
mtxt_password = (EditText)findViewById(R.id.editPassword);
mLogin = (Button)findViewById(R.id.button1);
mLogin.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String email = mtxt_email.getText().toString();
String password = mtxt_password.getText().toString();
System.out.println("Email id:-"+email);
System.out.println("Password:-"+password);
Intent dbintent = new Intent(this.getApplicationContext(),DbEntry.class);
dbintent.putExtra("p_email", email);
dbintent.putExtra("p_password", password);
startActivity(dbintent);
}
}
2)main.xml
This is login page gui.. also this file need one header.xml which include externally.......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/apple1" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textEmail_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="69dp"
android:text="Email ID"
android:textSize="20dp"
android:gravity="center|left"
android:textColor="@android:color/holo_purple" />
<EditText
android:id="@+id/editEmail_id"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="@+id/button1"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/textEmail_id"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/textPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textEmail_id"
android:layout_below="@+id/editEmail_id"
android:text="Password"
android:textSize="20dp"
android:textColor="@android:color/holo_purple" />
<EditText
android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="@+id/editEmail_id"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/textPassword"
android:layout_marginTop="10dp" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editPassword"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:background="@drawable/login" />
<include layout="@layout/header"/>
</RelativeLayout>
</LinearLayout>
3) header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:text="Welcome To @pple"
android:textSize="25dp"
android:textColor="@android:color/holo_purple" />
</LinearLayout>
4) DbEntry.java
Below code for database logic..... and show Dialog in second page check. it
package database.co.in;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.widget.Toast;
public class DbEntry extends Activity {
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
System.out.println("All iz well. ");
Intent getdbintent = getIntent();
String email = getdbintent.getStringExtra("p_email");
String password = getdbintent.getStringExtra("p_password");
db = openOrCreateDatabase("login.db",SQLiteDatabase.CREATE_IF_NECESSARY ,null);
String createTable = "CREATE TABLE IF NOT EXISTS info ("
+ "Emailid TEXT,"
+ "PassWord TEXT);";
db.execSQL(createTable);
String insertData = "INSERT or replace INTO info (Emailid, PassWord) VALUES('"+email+"','"+password+"')" ;
db.execSQL(insertData);
db.close();
System.out.println("All iz well.database has benn insert successfully. ");
Toast.makeText(getApplicationContext(), "welcome to o@k Tech"+email+"Password+"+password, Toast.LENGTH_LONG).show();
showDialog(1);
}
protected Dialog onCreateDialog(int i) {
Dialog dialog = null;
switch (i) {
case 1:
dialog = new Dialog(this);
dialog.setTitle("Welcome to O@k Tech...... ....");
dialog.setContentView(R.layout.dialog);
break;
default:
break;
}
return dialog;
}
}
5) dialog.xml
This file content only one button which is display on dialog box .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thanx to Login........." />
</LinearLayout>
6) AndroidManiFest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="database.co.in"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".DataBaseDemoActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".DbEntry" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Output and Require Backgroud images for this project.......:
this Application develop in api level- 15
ReplyDeletegoood......
ReplyDeleteya bro.... thanx............. kok divas banavo bhi android install kri ne
Deletenice tutorial bro.
ReplyDeleteYa thanx...... bro.... and biju kay new lage to ke abhi application banavine muku......
Deletebro...khub saras..m anroid begginer ...su bija koi simple demos 6?sqlite mate..please share karjo...ne..my id:"jigarce007@gmail.com"
ReplyDeletethanx bro..!