Android Form and Table Layout (With Tab functionality) .
![]() |
Android form submission into Table Layout. |
Today I have decided to post a simple Application about android form submission.
There are in total 8 java files , 5 xml files 2 images, 1 android manifest file to copy from.
So here goes;
First we start with MainActivity.java:
package com.example.databasesqllite; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.Toast; public class MainActivity extends Fragment { EditText name; RadioGroup gender, status; RadioButton gen, mstatus; Button submit, view; CheckBox ten, twe, btech; String tens = "", twes = "", btechs = ""; Myhelper myhelperobj; Spinner age; String g, s; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.activity_main, container, false); name = (EditText) rootView.findViewById(R.id.editText1); submit = (Button) rootView.findViewById(R.id.button1); // view = (Button) rootView.findViewById(R.id.button2); gender = (RadioGroup) rootView.findViewById(R.id.radioGroup1); age = (Spinner) rootView.findViewById(R.id.spinner1); status = (RadioGroup) rootView.findViewById(R.id.radioGroup2); ten = (CheckBox) rootView.findViewById(R.id.checkBox1); twe = (CheckBox) rootView.findViewById(R.id.checkBox2); btech = (CheckBox) rootView.findViewById(R.id.checkBox3); myhelperobj = new Myhelper(getActivity()); /* @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); name= (EditText) findViewById(R.id.editText1); submit = (Button) findViewById(R.id.button1); view = (Button) findViewById(R.id.button2); gender=(RadioGroup)findViewById(R.id.radioGroup1); age= (Spinner) findViewById(R.id.spinner1); status=(RadioGroup)findViewById(R.id.radioGroup2); ten= (CheckBox) findViewById(R.id.checkBox1); twe= (CheckBox) findViewById(R.id.checkBox2); btech= (CheckBox) findViewById(R.id.checkBox3);*/ submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { gen = (RadioButton) getActivity().findViewById(gender.getCheckedRadioButtonId()); mstatus = (RadioButton) getActivity().findViewById(status.getCheckedRadioButtonId()); g = gen.getText().toString(); s = mstatus.getText().toString(); if (ten.isChecked()) tens = "10"; if (twe.isChecked()) twes = "12"; if (btech.isChecked()) btechs = "btech"; String text = age.getSelectedItem().toString(); if (!name.getText().toString().equals("") && !text.equals("Select")) { SaveContact c = new SaveContact(); c.setName(name.getText().toString()); c.setgender(g); c.setmarital(s); c.setage(Integer.parseInt(text)); c.setqualification(tens); c.setqualification(twes); c.setqualification(btechs); myhelperobj.Insertdetail(c); Intent i = getActivity().getIntent(); getActivity().finish(); startActivity(i); //Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getActivity(), "Fill Up All Entries", Toast.LENGTH_SHORT).show(); } //Toast.makeText(getApplicationContext(), ""+name.getText().toString()+" "+g+" "+s+" "+tens+" "+twes+" "+btechs+" "+text, Toast.LENGTH_SHORT).show(); } }); /*view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startActivity(new Intent(getActivity(), viewallActivity.class)); } });*/ return rootView; } }
Then moving to the next class we have MyHelper.java
package com.example.databasesqllite; import java.util.ArrayList; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class Myhelper extends SQLiteOpenHelper { SQLiteDatabase db; private Context context; private static final int DATABASE_VERSION = 2; private static final String DATABASE_NAME = "information.db"; private static final String TABLE_NAME = "detail"; private static final String TABLE_NAME1 = "quali"; private static final String COLUMN_ID = "id"; private static final String COLUMN_DID = "did"; private static final String COLUMN_NAME = "name"; private static final String COLUMN_GENDER = "gender"; private static final String COLUMN_STATUS = "marital"; private static final String COLUMN_QUALIFI = "qualification"; private static final String COLUMN_AGE = "age"; private static final String TABLE_CREATE = "create table detail(id integer primary key AUTOINCREMENT not null, name text not null, gender text not null, marital text not null, age integer not null);"; private static final String TABLE_CREATE1 = "create table quali (id integer primary key AUTOINCREMENT not null, did integer not null, qualification text not null);"; public Myhelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; } @Override public void onCreate(SQLiteDatabase arg0) { // TODO Auto-generated method stub try { arg0.execSQL(TABLE_CREATE); arg0.execSQL(TABLE_CREATE1); this.db = arg0; } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } } @Override public void onUpgrade(SQLiteDatabase arg0, int oldversion, int newversion) { // TODO Auto-generated method stub try { String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME + ";"; String DROP_TABLE1 = "DROP TABLE IF EXISTS " + TABLE_NAME1 + ";"; arg0.execSQL(DROP_TABLE); arg0.execSQL(DROP_TABLE1); this.onCreate(db); } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } } public void Insertdetail(SaveContact c) { try { db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME, c.getName()); values.put(COLUMN_GENDER, c.getgender()); values.put(COLUMN_STATUS, c.getmarital()); values.put(COLUMN_AGE, c.getage()); long id = db.insert(TABLE_NAME, null, values); //String querys="select * from quali;"; ContentValues valuess = new ContentValues(); //Cursor cursors=db.rawQuery(querys, null); ArrayList<String> q = new ArrayList<String>(); q = c.getqualification(); //int counts=cursors.getCount(); for (int i = 0; i < q.size(); i++) { //valuess.put(COLUMN_ID, counts); valuess.put(COLUMN_DID, id); valuess.put(COLUMN_QUALIFI, q.get(i)); db.insert(TABLE_NAME1, null, valuess); //counts++; } db.close(); Message.message(context, "Inserted"); } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } } /* public void Insertsave(SaveContact c) { try{ db=this.getWritableDatabase(); String query="select * from quali;"; ContentValues values=new ContentValues(); Cursor cursor=db.rawQuery(query, null); int count=cursor.getCount(); values.put(COLUMN_ID, count); values.put(COLUMN_NAME, c.getName()); values.put(COLUMN_QUALIFI, c.getqualification()); db.insert(TABLE_NAME1, null, values); db.close(); } catch (Exception e) { // TODO: handle exception Message.message(context, ""+e); } }*/ public ArrayList<catgories> viewalls() { try { db = this.getReadableDatabase(); String query = "select id,name,gender,marital,age from " + TABLE_NAME + ";"; Cursor cursor = db.rawQuery(query, null); String id, name, gender, mar, age; ArrayList<catgories> personlist = new ArrayList<catgories>(); if (cursor.moveToFirst()) { do { String querys = "select did,qualification from " + TABLE_NAME1 + ";"; Cursor cursors = db.rawQuery(querys, null); ArrayList<String> q = new ArrayList<String>(); if (cursors.moveToFirst()) { do { if (cursor.getString(0).equals(cursors.getString(0))) { q.add(cursors.getString(1)); } } while (cursors.moveToNext()); } id = cursor.getString(0); name = cursor.getString(1); gender = cursor.getString(2); mar = cursor.getString(3); age = cursor.getString(4); catgories persons = new catgories(id, name, gender, mar, age, q); personlist.add(persons); } while (cursor.moveToNext()); } return personlist; } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } return null; } public ArrayList<catgories> getdata(String id) { try { db = this.getReadableDatabase(); String query = "select id,name,gender,marital,age from " + TABLE_NAME + ";"; Cursor cursor = db.rawQuery(query, null); String name, gender, mar, age; ArrayList<catgories> personlist = new ArrayList<catgories>(); if (cursor.moveToFirst()) { do { if (cursor.getString(0).equals(id)) { name = cursor.getString(1); gender = cursor.getString(2); mar = cursor.getString(3); age = cursor.getString(4); catgories persons = new catgories(name, gender, mar, age); personlist.add(persons); break; } } while (cursor.moveToNext()); } return personlist; } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } return null; } public ArrayList<catgories> getdatas(String id) { try { db = this.getReadableDatabase(); String query = "select id,did,qualification from " + TABLE_NAME1 + ";"; Cursor cursor = db.rawQuery(query, null); String qua; int tid; ArrayList<catgories> personlist = new ArrayList<catgories>(); if (cursor.moveToFirst()) { do { if (cursor.getString(1).equals(id)) { tid = Integer.parseInt(cursor.getString(0)); qua = cursor.getString(2); catgories persons = new catgories(tid, qua); personlist.add(persons); } } while (cursor.moveToNext()); } return personlist; } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } return null; } public void update(SaveContact c, String data) { try { db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME, c.getName()); values.put(COLUMN_GENDER, c.getgender()); values.put(COLUMN_STATUS, c.getmarital()); values.put(COLUMN_AGE, c.getage()); //db.insert(TABLE_NAME1, null, values); db.update(TABLE_NAME, values, COLUMN_ID + "= '" + data + "'", null); db.delete(TABLE_NAME1, COLUMN_DID + "= '" + data + "'", null); ContentValues valuess = new ContentValues(); ArrayList<String> q = new ArrayList<String>(); q = c.getqualification(); for (int i = 0; i < q.size(); i++) { valuess.put(COLUMN_DID, data); valuess.put(COLUMN_QUALIFI, q.get(i)); db.insert(TABLE_NAME1, null, valuess); } db.close(); Message.message(context, "Updated"); } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } } public void delete(int id) { try { db = this.getWritableDatabase(); db.delete(TABLE_NAME, COLUMN_ID + "= '" + id + "'", null); db.delete(TABLE_NAME1, COLUMN_DID + "= '" + id + "'", null); db.close(); Message.message(context, "Record Deleted"); } catch (Exception e) { // TODO: handle exception Message.message(context, "" + e); } } }
Now the third class SaveContacts.java
package com.example.databasesqllite; import java.util.ArrayList; public class SaveContact { String name, gender, marital; ArrayList<String> qualification = new ArrayList<String>(); int age; public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setgender(String gender) { this.gender = gender; } public String getgender() { return this.gender; } public void setmarital(String marital) { this.marital = marital; } public String getmarital() { return this.marital; } public void setqualification(String qualification) { if (qualification.equals("")) { return; } //this.qualification=qualification; this.qualification.add(qualification); } public ArrayList<String> getqualification() { return this.qualification; } public void setage(int age) { this.age = age; } public int getage() { return this.age; } }Moving ahead with the fourth class we have tabActivity.Java, now this app have Tab functionality too ,so the code goes like this :
package com.example.databasesqllite; import android.app.ActionBar; import android.app.Activity; import android.app.FragmentTransaction; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; public class tabActivity extends FragmentActivity implements ActionBar.TabListener { AppSectionsPagerAdapter mAppSectionsPagerAdapter; ViewPager mViewPager; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. actionBar.setHomeButtonEnabled(false); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab( actionBar.newTab() .setText(mAppSectionsPagerAdapter.getPageTitle(i)) .setTabListener(this)); } } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // When the given tab is selected, switch to the corresponding page in the ViewPager. mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { } public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { public AppSectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { switch (i) { case 0: // The first section of the app is the most interesting -- it offers // a launchpad into the other demonstrations in this example application. return new viewallActivity(); case 1: // The first section of the app is the most interesting -- it offers // a launchpad into the other demonstrations in this example application. return new MainActivity(); default: return new Fragment(); } } @Override public int getCount() { return 2; } @Override public CharSequence getPageTitle(int position) { if(position==0) { return "View Data"; } else if(position==1) { return "Insert"; } return "Section " + (position + 1); } } }
The fifth class is viewAllActivity.java
package com.example.databasesqllite; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class viewallActivity extends Fragment implements OnItemClickListener { ListView listView; ImageButton edit, delete; TextView t1, t2, t3, t4, t5; static String name; Myhelper myhelper; ArrayList<String> personlist; ArrayList<catgories> cat; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.viewall, container, false); listView = (ListView) rootView.findViewById(R.id.listView1); myhelper = new Myhelper(getActivity()); //getIntent(); cat = new ArrayList<catgories>(); personlist = new ArrayList<String>(); //personlist=myhelper.viewall(); cat = myhelper.viewalls(); CustomAdapter customAdapter = new CustomAdapter(cat); listView.setAdapter(customAdapter); // new CustomAdapter(); listView.setOnItemClickListener(this); return rootView; } /* @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.viewall); listView = (ListView) findViewById(R.id.listView1); getIntent(); cat = new ArrayList<catgories>(); personlist = new ArrayList<HashMap<String,String>>(); //personlist=myhelper.viewall(); cat = myhelper.viewalls(); CustomAdapter customAdapter = new CustomAdapter(cat); listView.setAdapter(customAdapter); // new CustomAdapter(); listView.setOnItemClickListener(this); }*/ @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { } public class CustomAdapter extends BaseAdapter { private ArrayList<catgories> innerClassBookArray; public CustomAdapter(ArrayList<catgories> paraBookArray) { innerClassBookArray = paraBookArray; } @Override public int getCount() { // TODO Auto-generated method stub return innerClassBookArray.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return innerClassBookArray.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { getActivity(); // LayoutInflater class is used to instantiate layout XML file into its corresponding View objects. LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = layoutInflater.inflate(R.layout.listitem, null); edit = (ImageButton) convertView.findViewById(R.id.button1); delete = (ImageButton) convertView.findViewById(R.id.button2); t1 = (TextView) convertView.findViewById(R.id.textView1); t2 = (TextView) convertView.findViewById(R.id.textView2); t3 = (TextView) convertView.findViewById(R.id.textView3); t4 = (TextView) convertView.findViewById(R.id.textView4); t5 = (TextView) convertView.findViewById(R.id.textView5); String str = innerClassBookArray.get(position).getName(); String str2 = innerClassBookArray.get(position).getname2(); String str3 = innerClassBookArray.get(position).getname3(); String str4 = innerClassBookArray.get(position).getname4(); ArrayList<String> q = innerClassBookArray.get(position).getq(); String str5 = ""; for (int i = 0; i < q.size(); i++) { if (i == q.size() - 1) str5 = str5 + q.get(i); else str5 = str5 + q.get(i) + ", "; } t1.setText(str); t2.setText(str2); t3.setText(str3); t4.setText(str4); t5.setText(str5); } final int pos = position; edit.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub name = innerClassBookArray.get(pos).getnum(); //Toast.makeText(getActivity(), ""+name, Toast.LENGTH_SHORT).show(); /*Intent i =new Intent(getActivity(), updateActivity.class); i.putExtra("key", name); startActivity(i);*/ Intent myIntent = new Intent(getActivity(), updateActivity.class); getActivity().startActivity(myIntent); } }); delete.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub name = innerClassBookArray.get(pos).getnum(); //Toast.makeText(getActivity(), ""+name, Toast.LENGTH_SHORT).show(); int n = Integer.parseInt(name); myhelper.delete(n); Intent i = getActivity().getIntent(); getActivity().finish(); startActivity(i); } }); return convertView; } } }
No. sixth is tada updateActivity:
package com.example.databasesqllite; import java.util.ArrayList; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.Toast; public class updateActivity extends Activity { EditText name; RadioGroup gender, status; RadioButton gen, mstatus; Button update; CheckBox ten, twe, btech; ArrayList<catgories> cat; ArrayList<catgories> catobj; String tens="", twes="", btechs=""; Myhelper myhelperobj=new Myhelper(this); Spinner age; String g,s; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.update); getActionBar().setDisplayHomeAsUpEnabled(true); name= (EditText) findViewById(R.id.editText1); update = (Button) findViewById(R.id.button1); gender=(RadioGroup)findViewById(R.id.radioGroup1); age= (Spinner) findViewById(R.id.spinner1); status=(RadioGroup)findViewById(R.id.radioGroup2); ten= (CheckBox) findViewById(R.id.checkBox1); twe= (CheckBox) findViewById(R.id.checkBox2); btech= (CheckBox) findViewById(R.id.checkBox3); RadioButton m = (RadioButton) findViewById(R.id.radio0); RadioButton f = (RadioButton) findViewById(R.id.radio1); RadioButton si = (RadioButton) findViewById(R.id.radio2); RadioButton ma = (RadioButton) findViewById(R.id.radio3); cat = new ArrayList<catgories>(); catobj = new ArrayList<catgories>(); // final String data = getIntent().getExtras().getString("key"); final String data = viewallActivity.name; cat=myhelperobj.getdata(data); name.setText(cat.get(0).getnum()); String mfgen=cat.get(0).getName().trim(); String marri= cat.get(0).getname2().trim(); String a=cat.get(0).getname3().trim(); if(mfgen.equals("Male")) { m.setChecked(true); } else { f.setChecked(true); } if(marri.equals("Single")) { si.setChecked(true); } else { ma.setChecked(true); } String[] cRaces = getResources().getStringArray(R.array.array_name); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cRaces); //selected item will look like a spinner set from XML spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); age.setAdapter(spinnerArrayAdapter); age.setSelection(spinnerArrayAdapter.getPosition(a)); catobj= myhelperobj.getdatas(data); for(int i=0;i<catobj.size();i++) { if(catobj.get(i).getName().toString().equals("10")) { ten.setChecked(true); } if(catobj.get(i).getName().toString().equals("12")) { twe.setChecked(true); } if(catobj.get(i).getName().toString().equals("btech")) { btech.setChecked(true); } //Toast.makeText(getApplicationContext(), ""+catobj.get(i).getName(),Toast.LENGTH_SHORT).show(); } update.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { gen = (RadioButton)findViewById(gender.getCheckedRadioButtonId()); mstatus = (RadioButton)findViewById(status.getCheckedRadioButtonId()); g=gen.getText().toString(); s=mstatus.getText().toString(); if(ten.isChecked()) tens="10"; // you can save this as checked somewhere if(twe.isChecked()) twes="12"; // you can save this as checked somewhere if(btech.isChecked()) btechs="btech"; // you can save this as checked somewhere String text = age.getSelectedItem().toString(); if(!name.getText().toString().equals("") && !text.equals("Select")) { SaveContact c=new SaveContact(); c.setName(name.getText().toString()); c.setgender(g); c.setmarital(s); c.setage(Integer.parseInt(text)); c.setqualification(tens); c.setqualification(twes); c.setqualification(btechs); myhelperobj.update(c,data); //Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Fill Up All Entries", Toast.LENGTH_SHORT).show(); } //Toast.makeText(getApplicationContext(), ""+name.getText().toString()+" "+g+" "+s+" "+tens+" "+twes+" "+btechs+" "+text, Toast.LENGTH_SHORT).show(); } }); } @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; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); viewallActivity.name=""; return true; default: return super.onOptionsItemSelected(item); } } @Override public void onBackPressed(){ viewallActivity.name=""; finish(); startActivity(new Intent(getApplicationContext(), tabActivity.class)); } }
Activity No. 7 catgories.java:
package com.example.databasesqllite; import java.util.ArrayList; public class catgories { private int id; private String name; private String num; private String name2; private String name3, name4; private ArrayList<String> q; public catgories() { } public catgories(int id, String name){ this.id = id; this.name = name; } public catgories(String num,String name, String name2, String name3){ this.num= num; this.name = name; this.name2 = name2; this.name3=name3; } public catgories(String num,String name, String name2, String name3,String name4){ this.num= num; this.name = name; this.name2 = name2; this.name3=name3; this.name4=name4; } public catgories(String num,String name, String name2, String name3,String name4,ArrayList<String> q){ this.num= num; this.name = name; this.name2 = name2; this.name3=name3; this.name4=name4; this.q=q; } public catgories(int id, String name, String num){ this.id = id; this.name = name; this.num =num; } public void setId(int id){ this.id = id; } public void setName(String name){ this.name = name; } public void setnum(String num){ this.num = num; } public void setname2(String name2){ this.name2 = name2; } public int getId(){ return this.id; } public String getName(){ return this.name; } public String getnum(){ return this.num; } public String getname2(){ return this.name2; } public String getname3(){ return this.name3; } public String getname4(){ return this.name4; } public ArrayList<String> getq(){ return this.q; } }
The last one is Message.java
package com.example.databasesqllite; import android.content.Context; import android.widget.Toast; public class Message { public static void message(Context context,String message) { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); } }
Layout Files
There are five Layout files.
1.activity_main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="20dp" android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " android:hint="Name" /> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Gender" android:textSize="17dp" /> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:orientation="horizontal" > <RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Male" android:textSize="15sp" /> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:checked="true" android:text="Female" android:textSize="15sp" /> </RadioGroup> <TextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Marital Status" android:textSize="17dp" /> <RadioGroup android:id="@+id/radioGroup2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:orientation="horizontal" > <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Single" android:textSize="15sp" /> <RadioButton android:id="@+id/radio3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:checked="true" android:text="Married" android:textSize="15sp" /> </RadioGroup> <TextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Qualification" android:textSize="17dp" /> <CheckBox android:id="@+id/checkBox1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:text="10th" /> <CheckBox android:id="@+id/checkBox2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:text="12th" /> <CheckBox android:id="@+id/checkBox3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:text="B.Tech." /> <TextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Age" android:textSize="17dp" /> <Spinner android:id="@+id/spinner1" android:layout_width="match_parent" android:entries="@array/array_name" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="Submit" /> </LinearLayout> </LinearLayout> </ScrollView> </LinearLayout>
2.listitem.xml
<?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="wrap_content" android:orientation="horizontal" android:padding="10dp" android:paddingLeft="10dp" android:paddingRight="10dp"> <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:paddingTop="6dip" android:layout_weight="1" android:textColor="#000000" android:text="jkj" /> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="kj" /> <TextView android:id="@+id/textView3" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="kj" /> <TextView android:id="@+id/textView4" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="kj" /> <TextView android:id="@+id/textView5" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="kj" /> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight="1"> <ImageButton android:id="@+id/button1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textColor="#000000" android:background="#00ffffff" android:src="@drawable/ic_menu_edit" /> <ImageButton android:id="@+id/button2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="#000000" android:background="#00ffffff" android:src="@drawable/ic_action_delete"/> </LinearLayout> </LinearLayout>
3.tab.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" />4.update.xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="20dp" android:hint="Name" /> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Gender" android:textSize="17dp" /> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:orientation="horizontal" > <RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Male" android:textSize="15sp" /> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:checked="true" android:text="Female" android:textSize="15sp" /> </RadioGroup> <TextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Marital Status" android:textSize="17dp" /> <RadioGroup android:id="@+id/radioGroup2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:orientation="horizontal" > <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Single" android:textSize="15sp" /> <RadioButton android:id="@+id/radio3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:checked="true" android:text="Married" android:textSize="15sp" /> </RadioGroup> <TextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Qualification" android:textSize="17dp" /> <CheckBox android:id="@+id/checkBox1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:text="10th" /> <CheckBox android:id="@+id/checkBox2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:text="12th" /> <CheckBox android:id="@+id/checkBox3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:text="B.Tech." /> <TextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:layout_marginTop="10dp" android:text="Age" android:textSize="17dp" /> <Spinner android:id="@+id/spinner1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" /> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="30dp" android:text="Update" /> </LinearLayout> </ScrollView> </LinearLayout>5. viewall<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:orientation="horizontal"> <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:paddingTop="6dip" android:layout_weight="1" android:textColor="#000000" android:text="Name" /> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="Gender" /> <TextView android:id="@+id/textView3" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="Marital Status" /> <TextView android:id="@+id/textView5" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="Age" /> <TextView android:id="@+id/textView6" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="Qualification" /> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight="1"> <TextView android:id="@+id/textView4" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" android:layout_weight="1" android:text="Action" /> </LinearLayout> </LinearLayout> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout>Lastly some xml in value1.dimens<resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen> </resources>2.string<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">databasesqllite</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string-array name="array_name"> <item >Select</item> <item>18</item> <item>19</item> <item>20</item> <item>21</item> <item>22</item> <item>23</item> <item>24</item> <item>25</item> <item>26</item> <item>27</item> <item>28</item> <item>29</item> <item>30</item> </string-array> </resources>3.style<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> </resources>Android Manifest
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.databasesqllite" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.databasesqllite.tabActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- <activity android:name="viewallActivity"></activity> --> <activity android:name="updateActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.databasesqllite.tabActivity" /> </activity> </application> </manifest>Images
ic_menu_edit.png
Fun fact you can covert these images to every compatible android screens by using an open source project on Github called Romanurik.
Hope you like it...Code by Kumkum Gupta.Posted by lol ik.
Comments
Post a Comment