i am new in android, in my application i need to create database and when user writing some thing into EditText then i need to save it into database but i actually don't know how i am gonna do it. so please somebody help me out.i already create submit button for save the data now i need to create just a database.
here i am giving one of my activity class named "Invitation.java" which contains
package com.ggit.trip.caster;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Invitation extends AppBaseActivity {
protected static final String Tag = "Invitation Activity";
private Button submit2;
private Button exit2;
private EditText Edit1;
private EditText Edit2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.invitation);
registerBaseActivityReceiver();
submit2 = (Button) findViewById(R.id.sub2_button1);
exit2=(Button)findViewById(R.id.button2);
Edit1 = (EditText) findViewById(R.id.editText1);
Edit2 = (EditText) findViewById(R.id.editText2);
submit2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Log.d(Tag, "EditText : " + Edit1.getText().toString());
Log.d(Tag, "EditText : " + Edit2.getText().toString());
Intent intent = new Intent(getApplicationContext(),
Registration.class);
startActivity(intent);
}
});
exit2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
closeAllActivities();
}
});
}
public void onDestroy() {
super.onDestroy();
unRegisterBaseActivityReceiver();
}
}
now here the xml layout for Invitation.jave class named "invitation.xml" contains
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sea_01"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:text="E-mail"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editText1"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:hint=" email address"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/editText1"
android:text="Phone"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editText2"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/textView2"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:hint=" phone number"
android:inputType="phone" />
<Button
android:id="@+id/sub2_button1"
android:layout_width="100dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textView1"
android:layout_marginRight="27dp"
android:background="@drawable/gloss_nine_patch"
android:text="Send Invitation" />
<Button
android:id="@+id/button2"
android:layout_width="100dp"
android:layout_height="45dp"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentBottom="true"
android:layout_marginLeft="32dp"
android:background="@drawable/gloss_nine_patch"
android:text="Exit" />
</RelativeLayout>
now I need to save the data into database for these two EditText.please write a proper or full activities class because i m a new guy. Thank you.
DataHelper.java for @Naser
package i.am.arnob;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class DataHelper extends SQLiteOpenHelper{
//database version, current ver is 1.
public static final int DATABASE_VER=1;
//database Name or db name
public static final String DATABASE_NAME="dataPerson";
//table Name, table person
public static final String TABLE_PERSON="person";
//table fields name,fist name,email and domain
//public static final String KEY_NAME="name";
//public static final String KEY_FIRST_NAME="first_name";
public static final String KEY_EMAIL="email";
public static final String KEY_DOMAIN="domain";
public DataHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
//creating string sqlTable for creating a table
String sqlTable = "create table " +TABLE_PERSON+ "("/* +KEY_NAME+ " text," +KEY_FIRST_NAME+ " text," */ +KEY_EMAIL+ " text," +KEY_DOMAIN+ " text);";
//db.execSQL() will execute string which we provide and will create a table with given table name and fields.
db.execSQL(sqlTable);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}