TabLayout in android.
package com.example.savetab;
import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
TabHost th;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
th=getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent =new Intent(this,Add.class);
spec=th.newTabSpec("naVEEN").setIndicator("Add Record").setContent(intent);
th.addTab(spec);
intent =new Intent(this,Listofname.class);
spec=th.newTabSpec("naVEEN").setIndicator("List Of Record").setContent(intent);
th.addTab(spec);
intent =new Intent(this,ShowonGrid.class);
spec=th.newTabSpec("naVEEN").setIndicator("Grid Of Record").setContent(intent);
th.addTab(spec);
th.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#8A4117"));
th.getTabContentView().getChildAt(0).setBackgroundColor(Color.parseColor("#8A4117"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
TabHost th;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
th=getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent =new Intent(this,Add.class);
spec=th.newTabSpec("naVEEN").setIndicator("Add Record").setContent(intent);
th.addTab(spec);
intent =new Intent(this,Listofname.class);
spec=th.newTabSpec("naVEEN").setIndicator("List Of Record").setContent(intent);
th.addTab(spec);
intent =new Intent(this,ShowonGrid.class);
spec=th.newTabSpec("naVEEN").setIndicator("Grid Of Record").setContent(intent);
th.addTab(spec);
th.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#8A4117"));
th.getTabContentView().getChildAt(0).setBackgroundColor(Color.parseColor("#8A4117"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
package com.example.savetab;
import android.os.Bundle;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Add extends Activity {
SQLiteDatabase db;
EditText name,mail,address,password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
db=openOrCreateDatabase("Mydb",MODE_PRIVATE, null);
db.execSQL("create table if not exists naveen(name varchar,mail varchar,address varchar,password varchar);");
name=(EditText)findViewById(R.id.editText1);
mail=(EditText)findViewById(R.id.editText2);
address=(EditText)findViewById(R.id.editText3);
password=(EditText)findViewById(R.id.editText4);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add, menu);
return true;
}
public void adddata(View v)
{
String n=name.getText().toString();
String m=mail.getText().toString();
String a=address.getText().toString();
String p=password.getText().toString();
db.execSQL("insert into naveen(name,mail,address,password) values('"+n+"','"+m+"','"+a+"','"+p+"');");
Toast.makeText(getApplicationContext(),"Saved Successfully",Toast.LENGTH_LONG).show();
}
public void reset(View v)
{
name.setText("");
mail.setText("");
address.setText("");
password.setText("");
}
}
package com.example.savetab;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Listofname extends Activity {
SQLiteDatabase db;
ListView li;
ArrayAdapter<String> aa;
String[] array={"Naveen","Rajput"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listofname);
li=(ListView) findViewById(R.id.listView1);
db=openOrCreateDatabase("Mydb",MODE_PRIVATE, null);
aa=new ArrayAdapter<String>(this,R.layout.items,R.id.rowTextView,view());
li.setAdapter(aa);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.listofname, menu);
return true;
}
public List<String> view()
{
//db.openOrCreateDatabase("Mydb", null);
List<String> list=new ArrayList<String>();
String selectQuery = "SELECT * FROM naveen";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
list.add(cursor.getString(0));
list.add(cursor.getString(1));
list.add(cursor.getString(2));
list.add(cursor.getString(3));
} while (cursor.moveToNext());
}
return list;
}
}
res/layout/activity_main.xml
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
res/layout/activity_add.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Add" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Name" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="15dp"
android:ems="10" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="21dp"
android:text="Mail" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/textView2"
android:layout_marginTop="25dp"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginTop="22dp"
android:text="Address" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_alignRight="@+id/editText2"
android:layout_below="@+id/textView3"
android:layout_marginTop="16dp"
android:ems="10" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText3"
android:layout_below="@+id/editText3"
android:layout_marginTop="21dp"
android:text="Password" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_alignRight="@+id/editText3"
android:layout_below="@+id/textView4"
android:layout_marginTop="18dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText4"
android:layout_below="@+id/editText4"
android:onClick="adddata"
android:text="Save" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@+id/button1"
android:onClick="reset"
android:text="Reset" />
</RelativeLayout>
res/layout/activity_listofname.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Listofname" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="29dp" >
</ListView>
</RelativeLayout>