Skip to main content
Output of tabhost with database insert delete update...etc

1..insert
2..delete
3.update
4.view

XML files...

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>


insert.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="Name" android:id="@+id/textView2" android:layout_width="wrap_content" android:textSize="20dp" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/edtNM" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="DESIG" android:id="@+id/textView3" android:layout_width="wrap_content" android:textSize="20dp" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/edtDESIG" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="phone" android:id="@+id/textView1" android:layout_width="wrap_content" android:textSize="20dp" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/edtPHONE" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_width="match_parent">
<Button android:layout_height="wrap_content" android:text="Save" android:id="@+id/button1" android:layout_width="76dp"></Button>
<Button android:text="Clear" android:id="@+id/btnClr" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>


detele.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Enter the name u want to delete" android:layout_width="wrap_content"></TextView>
<EditText android:id="@+id/edtdelete" android:hint="enter name to delete" android:layout_height="wrap_content" android:layout_width="match_parent">
<requestFocus></requestFocus>
</EditText>
<Button android:text="Delete" android:id="@+id/btnDelete" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</LinearLayout>


update.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView1" android:layout_width="wrap_content" android:text="ID" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/edtId" android:layout_width="wrap_content" android:hint="Enter id to update" android:layout_weight="0.95">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<Button android:text="Search" android:id="@+id/btnSearch" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_width="wrap_content" android:text="Name" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/edtName" android:layout_weight="1" android:layout_width="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView3" android:layout_width="wrap_content" android:text="Desig" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/edtDesig" android:layout_width="match_parent"></EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView4" android:layout_width="wrap_content" android:text="Phone" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/edtPhone" android:layout_weight="1" android:layout_width="wrap_content" android:inputType="phone"></EditText>
</LinearLayout>
<Button android:text="Update" android:id="@+id/btnUpdate" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</LinearLayout>


view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>




JavaFiles....

TabHostActivity.java
package com.abc;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;

public class TabhostActivity extends TabActivity implements TabContentFactory {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost th=getTabHost();
th.addTab(th.newTabSpec("tab1").setIndicator("Insert").setContent(new Intent(this,Insert1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
th.addTab(th.newTabSpec("tab1").setIndicator("Delete").setContent(new Intent(this,Delete1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
th.addTab(th.newTabSpec("tab1").setIndicator("Update").setContent(new Intent(this,Update1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
th.addTab(th.newTabSpec("tab1").setIndicator("View").setContent(new Intent(this,View1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));


}

@Override
public View createTabContent(String tag) {
// TODO Auto-generated method stub
return null;
}
}


Insert1.java
package com.abc;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.Contacts.Intents.Insert;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Insert1 extends Activity implements OnClickListener {
EditText Vname,Vdesig,Vphone;
Button save;
SQLiteDatabase db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.insert);
Vname=(EditText)findViewById(R.id.edtNM);
Vdesig=(EditText)findViewById(R.id.edtDESIG);
Vphone=(EditText)findViewById(R.id.edtPHONE);
save=(Button)findViewById(R.id.button1);

//save.setOnClickListener(this);
save.setOnClickListener(this);
db=openOrCreateDatabase("EMS.db",SQLiteDatabase.CREATE_IF_NECESSARY, null);
String sql="create table IF NOT EXISTS employee(id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,desig TEXT,phone TEXT)";
db.execSQL(sql);

}

@Override
public void onClick(View v) {

ContentValues cv=new ContentValues();
cv.put("name",Vname.getText().toString());
cv.put("desig",Vdesig.getText().toString());
cv.put("phone",Vphone.getText().toString());
db.insert("employee", null, cv);
Dialog d=new Dialog(this);
d.setTitle("confirm");

TextView tv=new TextView(this);

tv.setText("successfully added...");
d.setContentView(tv);
d.show();
//db.close();



}
public void onDestroy()
{
super.onDestroy();
db.close();
}
}



Delete1.java
package com.abc;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Delete1 extends Activity {
EditText Vedtdelete;
Button Vbtndelete;
SQLiteDatabase db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delete);
Vedtdelete=(EditText)findViewById(R.id.edtdelete);
Vbtndelete=(Button)findViewById(R.id.btnDelete);
db=openOrCreateDatabase("EMS.db",SQLiteDatabase.OPEN_READWRITE,null);
Vbtndelete.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
try
{
String sql="delete from employee where name='"+Vedtdelete.getText().toString()+"'";
db.execSQL(sql);

//db.delete("employee", "name="+Vedtdelete.getText().toString(),null );

}
catch(Exception e)
{
TextView t = new TextView(Delete1.this);
t.setText(e.toString());

Dialog d= new Dialog(Delete1.this);
d.setTitle("error");
d.setContentView(t);
d.show();
}

db.close();
}
});


}
/* public void onDestroy()
{
db.close();
}*/
}


Update1.java
package com.abc;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Update1 extends Activity
{
/** Called when the activity is first created. */
Button vupdate,vsearch;
EditText vid,vnm,vdesig,vphone;
String eid="0";
SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.update);
vupdate=(Button)findViewById(R.id.btnUpdate);
vsearch=(Button)findViewById(R.id.btnSearch);
vid=(EditText)findViewById(R.id.edtId);
vnm=(EditText)findViewById(R.id.edtName);
vdesig=(EditText)findViewById(R.id.edtDesig);
vphone=(EditText)findViewById(R.id.edtPhone);

db=openOrCreateDatabase("EMS.db",SQLiteDatabase.OPEN_READWRITE,null);
//vnm.setEnabled(false);
//vdesig.setEnabled(false);
//vphone.setEnabled(false);
// vupdate.setEnabled(false);
vsearch.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Cursor c=db.rawQuery("select name,desig,phone from employee where id="+vid.getText().toString(),null);
c.moveToFirst();
String s=c.getString(0);
vnm.setText(s);
vdesig.setText(c.getString(1));
vphone.setText(c.getString(2));

/*Dialog d=new Dialog(Update.this);
d.setTitle("confirm");
TextView tv=new TextView(Update.this);

tv.setText(s);
d.setContentView(tv);
d.show();*/
c.close();


}
});
vupdate.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//vupdate.setEnabled(true);


//vnm.setEnabled(true);
//vdesig.setEnabled(true);
// vphone.setEnabled(true);


String sql="update employee set name='"+vnm.getText().toString()+"',desig='"+vdesig.getText().toString()+"',phone='"+vphone.getText().toString()+"' where id="+vid.getText().toString()+"";
db.execSQL(sql);


Toast.makeText(getApplicationContext(), "Successfully updated...", Toast.LENGTH_LONG).show();

/* Dialog d=new Dialog(Update.this);
d.setTitle("confirm");
TextView tv=new TextView(Update.this);

tv.setText("successfully updated...");
d.setContentView(tv);
d.show();*/
// vnm.setText("");
//vdesig.setText("");
//vphone.setText("");
//vnm.requestFocus();
}
});

}

}



View1.java
package com.abc;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class View1 extends ListActivity {
SQLiteDatabase db;
Cursor c;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Toast.makeText(this,"hi",Toast.LENGTH_SHORT).show();
db=openOrCreateDatabase("EMS.db",SQLiteDatabase.OPEN_READONLY, null);
c=db.rawQuery("select * from employee",null);
ArrayList<String> list =new ArrayList<String>();
c.moveToFirst();
//if(c.getCount()>0)


while(c.moveToNext())
{
list.add(c.getString(0)+","+c.getString(1)+","+c.getString(2)+","+c.getString(3));
}


ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
getListView().setAdapter(ad);
c.close();

db.close();


// TextView tv=new TextView(View1.this);
//tv.setText(e.toString());


}
/*public void onDestroy()
{
c.close();
db.close();
}*/

}


2 Output of tabhost with database insert delete update...etc

1..insert
2..delete
3.update
4.view

XML files...

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>


insert.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="Name" android:id="@+id/textView2" android:layout_width="wrap_content" android:textSize="20dp" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/edtNM" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="DESIG" android:id="@+id/textView3" android:layout_width="wrap_content" android:textSize="20dp" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/edtDESIG" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="phone" android:id="@+id/textView1" android:layout_width="wrap_content" android:textSize="20dp" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/edtPHONE" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_width="match_parent">
<Button android:layout_height="wrap_content" android:text="Save" android:id="@+id/button1" android:layout_width="76dp"></Button>
<Button android:text="Clear" android:id="@+id/btnClr" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>


detele.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Enter the name u want to delete" android:layout_width="wrap_content"></TextView>
<EditText android:id="@+id/edtdelete" android:hint="enter name to delete" android:layout_height="wrap_content" android:layout_width="match_parent">
<requestFocus></requestFocus>
</EditText>
<Button android:text="Delete" android:id="@+id/btnDelete" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</LinearLayout>


update.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView1" android:layout_width="wrap_content" android:text="ID" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/edtId" android:layout_width="wrap_content" android:hint="Enter id to update" android:layout_weight="0.95">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<Button android:text="Search" android:id="@+id/btnSearch" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_width="wrap_content" android:text="Name" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/edtName" android:layout_weight="1" android:layout_width="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView3" android:layout_width="wrap_content" android:text="Desig" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/edtDesig" android:layout_width="match_parent"></EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_width="match_parent">
<TextView android:layout_height="wrap_content" android:id="@+id/textView4" android:layout_width="wrap_content" android:text="Phone" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/edtPhone" android:layout_weight="1" android:layout_width="wrap_content" android:inputType="phone"></EditText>
</LinearLayout>
<Button android:text="Update" android:id="@+id/btnUpdate" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</LinearLayout>


view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>




JavaFiles....

TabHostActivity.java
package com.abc;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;

public class TabhostActivity extends TabActivity implements TabContentFactory {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost th=getTabHost();
th.addTab(th.newTabSpec("tab1").setIndicator("Insert").setContent(new Intent(this,Insert1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
th.addTab(th.newTabSpec("tab1").setIndicator("Delete").setContent(new Intent(this,Delete1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
th.addTab(th.newTabSpec("tab1").setIndicator("Update").setContent(new Intent(this,Update1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
th.addTab(th.newTabSpec("tab1").setIndicator("View").setContent(new Intent(this,View1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));


}

@Override
public View createTabContent(String tag) {
// TODO Auto-generated method stub
return null;
}
}


Insert1.java
package com.abc;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.Contacts.Intents.Insert;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Insert1 extends Activity implements OnClickListener {
EditText Vname,Vdesig,Vphone;
Button save;
SQLiteDatabase db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.insert);
Vname=(EditText)findViewById(R.id.edtNM);
Vdesig=(EditText)findViewById(R.id.edtDESIG);
Vphone=(EditText)findViewById(R.id.edtPHONE);
save=(Button)findViewById(R.id.button1);

//save.setOnClickListener(this);
save.setOnClickListener(this);
db=openOrCreateDatabase("EMS.db",SQLiteDatabase.CREATE_IF_NECESSARY, null);
String sql="create table IF NOT EXISTS employee(id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,desig TEXT,phone TEXT)";
db.execSQL(sql);

}

@Override
public void onClick(View v) {

ContentValues cv=new ContentValues();
cv.put("name",Vname.getText().toString());
cv.put("desig",Vdesig.getText().toString());
cv.put("phone",Vphone.getText().toString());
db.insert("employee", null, cv);
Dialog d=new Dialog(this);
d.setTitle("confirm");

TextView tv=new TextView(this);

tv.setText("successfully added...");
d.setContentView(tv);
d.show();
//db.close();



}
public void onDestroy()
{
super.onDestroy();
db.close();
}
}



Delete1.java
package com.abc;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Delete1 extends Activity {
EditText Vedtdelete;
Button Vbtndelete;
SQLiteDatabase db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delete);
Vedtdelete=(EditText)findViewById(R.id.edtdelete);
Vbtndelete=(Button)findViewById(R.id.btnDelete);
db=openOrCreateDatabase("EMS.db",SQLiteDatabase.OPEN_READWRITE,null);
Vbtndelete.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
try
{
String sql="delete from employee where name='"+Vedtdelete.getText().toString()+"'";
db.execSQL(sql);

//db.delete("employee", "name="+Vedtdelete.getText().toString(),null );

}
catch(Exception e)
{
TextView t = new TextView(Delete1.this);
t.setText(e.toString());

Dialog d= new Dialog(Delete1.this);
d.setTitle("error");
d.setContentView(t);
d.show();
}

db.close();
}
});


}
/* public void onDestroy()
{
db.close();
}*/
}


Update1.java
package com.abc;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Update1 extends Activity
{
/** Called when the activity is first created. */
Button vupdate,vsearch;
EditText vid,vnm,vdesig,vphone;
String eid="0";
SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.update);
vupdate=(Button)findViewById(R.id.btnUpdate);
vsearch=(Button)findViewById(R.id.btnSearch);
vid=(EditText)findViewById(R.id.edtId);
vnm=(EditText)findViewById(R.id.edtName);
vdesig=(EditText)findViewById(R.id.edtDesig);
vphone=(EditText)findViewById(R.id.edtPhone);

db=openOrCreateDatabase("EMS.db",SQLiteDatabase.OPEN_READWRITE,null);
//vnm.setEnabled(false);
//vdesig.setEnabled(false);
//vphone.setEnabled(false);
// vupdate.setEnabled(false);
vsearch.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Cursor c=db.rawQuery("select name,desig,phone from employee where id="+vid.getText().toString(),null);
c.moveToFirst();
String s=c.getString(0);
vnm.setText(s);
vdesig.setText(c.getString(1));
vphone.setText(c.getString(2));

/*Dialog d=new Dialog(Update.this);
d.setTitle("confirm");
TextView tv=new TextView(Update.this);

tv.setText(s);
d.setContentView(tv);
d.show();*/
c.close();


}
});
vupdate.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//vupdate.setEnabled(true);


//vnm.setEnabled(true);
//vdesig.setEnabled(true);
// vphone.setEnabled(true);


String sql="update employee set name='"+vnm.getText().toString()+"',desig='"+vdesig.getText().toString()+"',phone='"+vphone.getText().toString()+"' where id="+vid.getText().toString()+"";
db.execSQL(sql);


Toast.makeText(getApplicationContext(), "Successfully updated...", Toast.LENGTH_LONG).show();

/* Dialog d=new Dialog(Update.this);
d.setTitle("confirm");
TextView tv=new TextView(Update.this);

tv.setText("successfully updated...");
d.setContentView(tv);
d.show();*/
// vnm.setText("");
//vdesig.setText("");
//vphone.setText("");
//vnm.requestFocus();
}
});

}

}



View1.java
package com.abc;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class View1 extends ListActivity {
SQLiteDatabase db;
Cursor c;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Toast.makeText(this,"hi",Toast.LENGTH_SHORT).show();
db=openOrCreateDatabase("EMS.db",SQLiteDatabase.OPEN_READONLY, null);
c=db.rawQuery("select * from employee",null);
ArrayList<String> list =new ArrayList<String>();
c.moveToFirst();
//if(c.getCount()>0)


while(c.moveToNext())
{
list.add(c.getString(0)+","+c.getString(1)+","+c.getString(2)+","+c.getString(3));
}


ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
getListView().setAdapter(ad);
c.close();

db.close();


// TextView tv=new TextView(View1.this);
//tv.setText(e.toString());


}
/*public void onDestroy()
{
c.close();
db.close();
}*/

}


Comments

Popular posts from this blog

Laravel Free Admin Panel UI and Code

Thanks for share  https://github.com/the-control-group/voyager V oyager - The Missing Laravel Admin Made with  ❤️  by  The Control Group Website & Documentation:  https://voyager.devdojo.com/ Video Tutorial Here:  https://voyager.devdojo.com/academy/ Join our Slack chat:  https://voyager-slack-invitation.herokuapp.com/ View the Voyager Cheat Sheet:  https://voyager-cheatsheet.ulties.com/ Laravel Admin & BREAD System (Browse, Read, Edit, Add, & Delete), supporting Laravel 6 and newer! Want to use Laravel 5? Use  Voyager 1.3 Installation Steps 1. Require the Package After creating your new Laravel application you can include the Voyager package with the following command: composer require tcg/voyager 2. Add the DB Credentials & APP_URL Next make sure to create a new database and add your database credentials to your .env file: DB_HOST=localhost DB_DATABASE=homestead DB_USERNAME=homestead DB...

How To Install And Setup Laravel Latest Version On Windows 10 Using XAMPP

How to install Laravel on Windows using XAMPP Laravel, one of the best PHP framework is getting more popular among developers all around the world. The Model-View-Controller architecture and blade templating engine made Laravel simple and powerful. Here we are going to discuss the steps of installation and setup of Laravel 5.7 on Windows 10 using XAMPP. Installation Follow the steps below to start installing Laravel 5.7 on Windows 10: 1. Install XAMPP XAMPP is the most popular PHP development environment.XAMPP is a completely free, easy to install Apache distribution containing MariaDB, PHP, and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use. XAMPP can be easily installed using the link below. https://www.apachefriends.org/download.html Laravel 5.7 requires PHP >= 7.1.3. Download the latest version (7.3.3/PHP 7.3.3). I have shown some screenshots of the installation steps below. 2. Start Apache and MySQ...
Share Application - Any social  app  Facebook,Twitter,Instagram,Youtube,Google+....etc.                                      Pate Prashant    Android Code For share any application. Share code for Video,Image,Text.  share on (Twitter,Facebook,Instagram,Google+,Youtube) Some packeges of application name Application Name                                                Package Name Twitter                         ...