Update Database in Android Studio

Introduction

 
This article is a continuation of my article titled "Insert, Delete and View functionalities in Database through Android Studio". In the previous article, you saw how to implement the addition, deletion and view functionalities in a database. I used a bank database for this purpose. Admin functionalities were already implemented. Today, we will make customer functionalities, in other words, withdraw cash, deposit cash, and view account details.
 
For withdrawing and depositing, basically the database needs to be updated.
 
Step 1
 
Add the following code to the previously edited "string.xl":
  1. <string name="custom">Customer</string>  
  2. <string name="custtxt">Welcome Customer.....</string> 
Note that the other files in "values", in other words, "color.xml", "dimens.xml" and "styles.xml" remain the same.
 
Step 2
 
For beautification, all my buttons will use the following drawable resource as their background. Right-click on "Drawable" -> "New" -> "Drawable resource file". Name this file as "admin_design" and add the following to it:
  1. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  2.   <item android:state_enabled="false" >  
  3.     <shape android:shape="rectangle">  
  4.       <gradient  
  5.               android:startColor="#454545"  
  6.               android:endColor="#454545"  
  7.               android:angle="-90"  
  8.               android:type="linear"  
  9.                     />  
  10.       <corners android:radius="5dp" />  
  11.     </shape>  
  12.   </item>  
  13.    
  14.   <!-- pressed -->  
  15.   <item android:state_pressed="true" android:state_enabled="true" >  
  16.     <shape android:shape="rectangle">  
  17.       <gradient  
  18.               android:startColor="#64334C"  
  19.               android:endColor="#300019"  
  20.               android:angle="-90"  
  21.               android:type="linear"  
  22.                     />  
  23.       <corners android:radius="5dp" />  
  24.     </shape>  
  25.   </item>  
  26.    
  27.   <!-- focused -->  
  28.   <item android:state_focused="true">  
  29.     <shape android:shape="rectangle">  
  30.       <gradient  
  31.               android:startColor="#C76699"  
  32.               android:endColor="#d9c292"  
  33.               android:angle="-90"  
  34.               android:type="linear"  
  35.                     />  
  36.       <corners android:radius="5dp" />  
  37.       <stroke android:width="2dp" android:color="#dddddd"/>  
  38.     </shape>  
  39.   </item>  
  40.    
  41.   <!-- default -->  
  42.   <item>  
  43.     <shape android:shape="rectangle">  
  44.       <gradient  
  45.               android:startColor="#C76699"  
  46.               android:endColor="#d9c292"  
  47.               android:angle="-90"  
  48.               android:type="linear"  
  49.                     />  
  50.       <corners android:radius="5dp" />  
  51.     </shape>  
  52.   </item>  
  53.    
  54. </selector> 
Step 3
 
Now let us make the customer page layout. Right-click on "Layout" -> "New" -> "Layout resource file". Name this file as "customer_layout". Add the following code to this XML file (inside the LinearLayout element):
  1. <TextView  
  2.             android:layout_width="wrap_content"  
  3.             android:layout_height="wrap_content"  
  4.             android:text="@string/custtxt"  
  5.             android:layout_marginLeft="40dp"  
  6.             android:textColor="@color/txt"  
  7.             android:layout_marginTop="20dp"  
  8.             android:textSize="@dimen/wel_admin"  
  9.             />  
  10.    
  11. <Button  
  12.         android:layout_height="wrap_content"  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_marginTop="20dp"  
  15.         android:layout_marginLeft="10dp"  
  16.         android:text="Back To Main Menu"  
  17.         android:background="@drawable/admin_design"  
  18.         android:paddingLeft="10dp"  
  19.         android:paddingRight="10dp"  
  20.         android:id="@+id/backcust"  
  21.             />  
  22. <Button  
  23.         android:id="@+id/withdaw"  
  24.         android:layout_height="wrap_content"  
  25.         android:layout_width="wrap_content"  
  26.         android:layout_marginTop="70dp"  
  27.         android:layout_marginLeft="40dp"  
  28.         android:background="@drawable/admin_design"  
  29.         android:text="Withdraw"  
  30.         android:paddingLeft="10dp"  
  31.         android:paddingRight="10dp"  
  32.             />  
  33.    
  34. <Button  
  35.         android:id="@+id/deposit"  
  36.         android:layout_height="wrap_content"  
  37.         android:layout_width="wrap_content"  
  38.         android:layout_marginTop="70dp"  
  39.         android:layout_marginLeft="40dp"  
  40.         android:background="@drawable/admin_design"  
  41.         android:text="Deposit"  
  42.         android:paddingLeft="10dp"  
  43.         android:paddingRight="10dp"/>  
  44.    
  45. <Button  
  46.         android:id="@+id/cview"  
  47.         android:layout_height="wrap_content"  
  48.         android:layout_width="wrap_content"  
  49.         android:layout_marginTop="70dp"  
  50.         android:layout_marginLeft="40dp"  
  51.         android:background="@drawable/admin_design"  
  52.         android:text="View"  
  53.         android:paddingLeft="10dp"  
  54.         android:paddingRight="10dp"/> 
The layout looks like:
 
c1.jpg
 
Step 4
 
To create a layout for withdrawing the cash: right-click on "Layout" -> "New" -> "Layout resource file". Name this file "withdraw_layout" and add the following to it:
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.               android:orientation="vertical"  
  3.               android:layout_width="match_parent"  
  4.               android:layout_height="match_parent"  
  5.               android:background="@drawable/withdarw">  
  6.   <TextView  
  7.       android:layout_height="wrap_content"  
  8.       android:layout_width="fill_parent"  
  9.       android:text="Withdraw the cash....."  
  10.       android:layout_marginTop="30dp"  
  11.       android:layout_marginLeft="10dp"  
  12.       android:layout_marginBottom="40dp"  
  13.       android:textSize="30dp"  
  14.         />  
  15.    
  16.   <RelativeLayout  
  17.       android:layout_height="wrap_content"  
  18.       android:layout_width="fill_parent">  
  19.    
  20.     <TextView  
  21.         android:id="@+id/t1"  
  22.         android:layout_height="wrap_content"  
  23.         android:layout_width="wrap_content"  
  24.         android:text="Your Id:"  
  25.         android:textSize="@dimen/form_ele"  
  26.         android:layout_marginLeft="10dp"/>  
  27.     <EditText  
  28.         android:layout_height="wrap_content"  
  29.         android:layout_width="fill_parent"  
  30.         android:layout_toRightOf="@id/t1"  
  31.         android:layout_marginLeft="20dp"  
  32.         android:layout_marginRight="10dp"  
  33.         android:id="@+id/wid"/>  
  34.    
  35.   </RelativeLayout>  
  36.    
  37.   <RelativeLayout  
  38.           android:layout_height="wrap_content"  
  39.           android:layout_width="fill_parent"  
  40.           android:layout_marginTop="20dp">  
  41.    
  42.     <TextView  
  43.             android:id="@+id/t2"  
  44.             android:layout_height="wrap_content"  
  45.             android:layout_width="wrap_content"  
  46.             android:text="Amount:"  
  47.             android:textSize="@dimen/form_ele"  
  48.             android:layout_marginLeft="10dp"/>  
  49.     <EditText  
  50.             android:layout_height="wrap_content"  
  51.             android:layout_width="fill_parent"  
  52.             android:layout_toRightOf="@id/t2"  
  53.             android:layout_marginLeft="20dp"  
  54.             android:layout_marginRight="10dp"  
  55.             android:id="@+id/wamt"/>  
  56.    
  57.   </RelativeLayout>  
  58.    
  59.   <Button  
  60.       android:layout_height="wrap_content"  
  61.       android:layout_width="wrap_content"  
  62.       android:text="Withdraw"  
  63.       android:layout_marginTop="80dp"  
  64.       android:layout_marginLeft="110dp"  
  65.       android:background="@drawable/admin_design"  
  66.       android:paddingRight="10dp"  
  67.       android:paddingLeft="10dp"  
  68.       android:id="@+id/bwithdraw"/>  
  69.    
  70. </LinearLayout> 
Note that in this layout I have used an image as the background. The method is the same. Copy the image you want to be the background to the clipboard and paste it in the "drawable" folders.
 
The layout looks like:
 
c2.jpg
 
Step 5
 
Similarly, create a layout file for depositing cash and name it "deposit_layout". Add the following code to it (inside the LinearLayout element):
  1. <TextView  
  2.             android:layout_height="wrap_content"  
  3.             android:layout_width="fill_parent"  
  4.             android:text="Deposit the cash....."  
  5.             android:layout_marginTop="30dp"  
  6.             android:layout_marginLeft="10dp"  
  7.             android:layout_marginBottom="40dp"  
  8.             android:textSize="30dp"  
  9.             />  
  10.    
  11. <RelativeLayout  
  12.         android:layout_height="wrap_content"  
  13.         android:layout_width="fill_parent">  
  14.    
  15.   <TextView  
  16.           android:id="@+id/t3"  
  17.           android:layout_height="wrap_content"  
  18.           android:layout_width="wrap_content"  
  19.           android:text="Your Id:"  
  20.           android:textSize="@dimen/form_ele"  
  21.           android:layout_marginLeft="10dp"/>  
  22.   <EditText  
  23.           android:layout_height="wrap_content"  
  24.           android:layout_width="fill_parent"  
  25.           android:layout_toRightOf="@id/t3"  
  26.           android:layout_marginLeft="20dp"  
  27.           android:layout_marginRight="10dp"  
  28.           android:id="@+id/did"/>  
  29.    
  30. </RelativeLayout>  
  31.    
  32. <RelativeLayout  
  33.         android:layout_height="wrap_content"  
  34.         android:layout_width="fill_parent"  
  35.         android:layout_marginTop="20dp">  
  36.    
  37.   <TextView  
  38.           android:id="@+id/t4"  
  39.           android:layout_height="wrap_content"  
  40.           android:layout_width="wrap_content"  
  41.           android:text="Amount:"  
  42.           android:textSize="@dimen/form_ele"  
  43.           android:layout_marginLeft="10dp"/>  
  44.   <EditText  
  45.           android:layout_height="wrap_content"  
  46.           android:layout_width="fill_parent"  
  47.           android:layout_toRightOf="@id/t4"  
  48.           android:layout_marginLeft="10dp"  
  49.           android:layout_marginRight="10dp"  
  50.           android:id="@+id/damt"/>  
  51.    
  52. </RelativeLayout>  
  53.    
  54. <Button  
  55.         android:layout_height="wrap_content"  
  56.         android:layout_width="wrap_content"  
  57.         android:text="Deposit"  
  58.         android:layout_marginTop="80dp"  
  59.         android:layout_marginLeft="110dp"  
  60.         android:background="@drawable/admin_design"  
  61.         android:paddingRight="10dp"  
  62.         android:paddingLeft="10dp"  
  63.         android:id="@+id/bdeposit"/> 
The layout looks like
 
c3.jpg
 
Step 6
 
Create a layout file for depositing cash and name it as "cview_layout". Add the following code to it (inside the LinearLayout element):
  1. <TextView  
  2.             android:layout_width="wrap_content"  
  3.             android:layout_height="wrap_content"  
  4.             android:text="View account...."  
  5.             android:layout_marginLeft="60dp"  
  6.             android:layout_marginTop="20dp"  
  7.             android:textSize="@dimen/wel_admin"  
  8.             />  
  9. <RelativeLayout  
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="wrap_content">  
  12.    
  13.   <TextView  
  14.           android:id="@+id/d1"  
  15.           android:layout_width="wrap_content"  
  16.           android:layout_height="wrap_content"  
  17.           android:text="Acc id: "  
  18.           android:layout_marginLeft="20dp"  
  19.           android:layout_marginTop="60dp"  
  20.           android:textSize="@dimen/form_ele"/>  
  21.   <EditText  
  22.           android:id="@+id/cidv"  
  23.           android:layout_height="wrap_content"  
  24.           android:layout_width="fill_parent"  
  25.           android:layout_marginTop="60dp"  
  26.           android:layout_toRightOf="@id/t1"  
  27.           android:layout_marginLeft="110dp"/>  
  28. </RelativeLayout>  
  29.    
  30. <Button  
  31.         android:id="@+id/bview"  
  32.         android:layout_height="wrap_content"  
  33.         android:layout_width="wrap_content"  
  34.         android:layout_marginTop="80dp"  
  35.         android:layout_marginLeft="130dp"  
  36.         android:text="View"  
  37.         android:background="@drawable/admin_design"/> 
The layout looks like:
 
c4.jpg
 
Step 7
 
I am creating yet another layout for viewing the database. The previous layout was asking for the user id. This layout will display the details of the customer depending upon the id provided by the user.
 
In the same way, create another layout file and name it "cview_layout2". Add the following code to it (inside the LinearLayout element):
  1. <TextView  
  2.     android:layout_height="fill_parent"  
  3.     android:layout_width="fill_parent"  
  4.     android:id="@+id/lav"  
  5.     android:layout_marginTop="30dp"  
  6.     android:layout_marginLeft="20dp"  
  7.     android:layout_marginRight="20dp"  
  8.     android:layout_marginBottom="30dp"/> 
The layout looks like:
 
c5.jpg
 
Now let us start with the Java part.
 
Step 8
 
Go to the "MainActivity" Java file (already modified for the Admin functionalities) and add the following code to it
  1. Button b2;  
  2. b2=(Button)findViewById(R.id.customer);  
  3.         b2.setOnClickListener(new View.OnClickListener() {  
  4.             @Override  
  5.             public void onClick(View v) {  
  6.                 Intent i=new Intent(context,Customer.class);  
  7.                 startActivity(i);  
  8.             }  
  9.         }); 
Here we have just added the click event for the customer button.
 
Step 9
 
In the same package, right-click then select "New" -> "Java class". Name this file as "Customer" and add the following code to it:
  1. package com.example.bankdb;  
  2.    
  3. import android.app.Activity;  
  4. import android.content.Context;  
  5. import android.content.Intent;  
  6. import android.os.Bundle;  
  7. import android.view.View;  
  8. import android.widget.Button;  
  9.    
  10. public class Customer extends Activity {  
  11.     Button w;  
  12.     Button d;  
  13.     Button v;  
  14.     Button backc;  
  15.     @Override  
  16.     protected void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.customer_layout);  
  19.         final Context context=this;  
  20.         w=(Button)findViewById(R.id.withdaw);  
  21.         d=(Button)findViewById(R.id.deposit);  
  22.         v=(Button)findViewById(R.id.cview);  
  23.         backc=(Button)findViewById(R.id.backcust);  
  24.    
  25.         w.setOnClickListener(new View.OnClickListener() {  
  26.             @Override  
  27.             public void onClick(View v) {  
  28.                 Intent i=new Intent(context, Withdraw.class);  
  29.                 startActivity(i);  
  30.             }  
  31.         });  
  32.    
  33.         d.setOnClickListener(new View.OnClickListener() {  
  34.             @Override  
  35.             public void onClick(View v) {  
  36.                 Intent i=new Intent(context, Deposit.class);  
  37.                 startActivity(i);  
  38.             }  
  39.         });  
  40.    
  41.         v.setOnClickListener(new View.OnClickListener() {  
  42.             @Override  
  43.             public void onClick(View v) {  
  44.                 Intent i=new Intent(context, Cview.class);  
  45.                 startActivity(i);  
  46.             }  
  47.         });  
  48.    
  49.         backc.setOnClickListener(new View.OnClickListener() {  
  50.             @Override  
  51.             public void onClick(View v) {  
  52.                 finish();  
  53.             }  
  54.         });  
  55.     }  
Note the use of "finish()". This function finishes the current activity and loads the activity that had called this activity.
 
Step 10
 
Create a new Java class in the same way. Name it as "Withdraw" and add the following code to it:
  1. package com.example.bankdb;  
  2.    
  3. import android.app.Activity;  
  4. import android.content.Context;  
  5. import android.content.Intent;  
  6. import android.database.Cursor;  
  7. import android.database.sqlite.SQLiteDatabase;  
  8. import android.os.Bundle;  
  9. import android.util.Log;  
  10. import android.view.View;  
  11. import android.widget.Button;  
  12. import android.widget.EditText;  
  13. import android.widget.Toast;  
  14.    
  15. public class Withdraw extends Activity {  
  16.     Button b;  
  17.     EditText wid;  
  18.     EditText wamt;  
  19.     SQLiteDatabase db;  
  20.     String s;  
  21.     @Override  
  22.     protected void onCreate(Bundle savedInstanceState) {  
  23.         super.onCreate(savedInstanceState);  
  24.         setContentView(R.layout.withdraw_layout);  
  25.         final Context context=this;  
  26.         wid=(EditText)findViewById(R.id.wid);  
  27.         wamt=(EditText)findViewById(R.id.wamt);  
  28.         b=(Button)findViewById(R.id.bwithdraw);  
  29.         b.setOnClickListener(new View.OnClickListener() {  
  30.             @Override  
  31.             public void onClick(View v) {  
  32.                 try  
  33.                 {  
  34.                     String t=wid.getText().toString();  
  35.                     int t4=Integer.parseInt(t);  
  36.                     int t5=Integer.parseInt(wamt.getText().toString());  
  37.                     db=openOrCreateDatabase("Banking1",SQLiteDatabase.CREATE_IF_NECESSARY,null);  
  38.                     Cursor c= db.rawQuery("SELECT * FROM bank where id="+t,null);  
  39.                     c.moveToFirst();  
  40.                     int flag=0;  
  41.                      s="Withdraw";  
  42.                     Comman.fun(s);  
  43.                     while(! c.isAfterLast())  
  44.                     {  
  45.                         int t2=Integer.parseInt(c.getString(0));  
  46.                         int t3=Integer.parseInt(c.getString(2));  
  47.                         if(t4==t2)  
  48.                         {  
  49.                             flag=1;  
  50.                             if((t3-t5)>0)  
  51.                             {  
  52.                                 int temp=t3-t5;  
  53.                                 db.execSQL("UPDATE bank SET bal="+temp+" WHERE id="+t4);  
  54.                                 Comman.fun("Withdraw","Problem updating..");  
  55.                                 Toast.makeText(Withdraw.this"Withdrawn......"2000).show();  
  56.                             }  
  57.                             else  
  58.                             {  
  59.                                 Toast.makeText(Withdraw.this"Not enough cash......"2000).show();  
  60.                             }  
  61.                         }  
  62.    
  63.                         c.moveToNext();  
  64.                     }  
  65.                     if(flag==0)  
  66.                     {  
  67.                             Toast.makeText(Withdraw.this"Invalid Id............."2000).show();  
  68.    
  69.                     }  
  70.                     wid.setText("");  
  71.                     wamt.setText("");  
  72.                     //Intent i=new Intent(context,Customer.class);  
  73.                     //startActivity(i);  
  74.                     finish();  
  75.                 }  
  76.                 catch(Exception e)  
  77.                 {  
  78.                     
  79.                 }  
  80.    
  81.             }  
  82.    
  83.         });  
  84.    
  85.     }  
Step 11
 
Create another activity and name it "Deposit". Add the following to it:
  1. package com.example.bankdb;  
  2.    
  3. import android.app.Activity;  
  4. import android.content.Context;  
  5. import android.content.Intent;  
  6. import android.database.Cursor;  
  7. import android.database.sqlite.SQLiteDatabase;  
  8. import android.os.Bundle;  
  9. import android.view.View;  
  10. import android.widget.Button;  
  11. import android.widget.EditText;  
  12. import android.widget.Toast;  
  13.    
  14. public class Deposit extends Activity {  
  15.    
  16.     Button b;  
  17.     EditText did;  
  18.     EditText damt;  
  19.     SQLiteDatabase db;  
  20.    
  21.     @Override  
  22.     protected void onCreate(Bundle savedInstanceState) {  
  23.         super.onCreate(savedInstanceState);  
  24.         setContentView(R.layout.deposit_layout);  
  25.         final Context context=this;  
  26.         did=(EditText)findViewById(R.id.did);  
  27.         damt=(EditText)findViewById(R.id.damt);  
  28.         b=(Button)findViewById(R.id.bdeposit);  
  29.         b.setOnClickListener(new View.OnClickListener() {  
  30.             @Override  
  31.             public void onClick(View v) {  
  32.                 try  
  33.                 {  
  34.                     int flag=0;  
  35.                     String t=did.getText().toString();  
  36.                     int t4=Integer.parseInt(t);  
  37.                     int t5=Integer.parseInt(damt.getText().toString());  
  38.                     db=openOrCreateDatabase("Banking1",SQLiteDatabase.CREATE_IF_NECESSARY,null);  
  39.                     Cursor c= db.rawQuery("SELECT * FROM bank where id="+t,null);  
  40.                     c.moveToFirst();  
  41.                     while(! c.isAfterLast())  
  42.                     {  
  43.                         int t2=Integer.parseInt(c.getString(0));  
  44.                         int t3=Integer.parseInt(c.getString(2));  
  45.                         if(t4==t2)  
  46.                         {  
  47.                                 int temp=t5+t3;  
  48.                                 db.execSQL("UPDATE bank SET bal="+temp+" WHERE id="+t4);  
  49.                                 Toast.makeText(Deposit.this"Deposited......"2000).show();  
  50.                                 flag=1;  
  51.                         }  
  52.    
  53.                         c.moveToNext();  
  54.                     }  
  55.                     if(flag==0)  
  56.                     {  
  57.                         Toast.makeText(Deposit.this"Invalid Id............."2000).show();  
  58.    
  59.                     }  
  60.                     did.setText("");  
  61.                     damt.setText("");  
  62.                     //Intent i=new Intent(context,Customer.class);  
  63.                     //startActivity(i);  
  64.                 }  
  65.                 catch(Exception e)  
  66.                 {  
  67.                     e.printStackTrace();  
  68.                 }  
  69.                 finish();  
  70.    
  71.             }  
  72.         });  
  73.    
  74.     }  
Step 12
 
Create an activity for viewing the database. Name this activity as "Cview". Add the following to it:
  1. package com.example.bankdb;  
  2.    
  3. import android.app.Activity;  
  4. import android.content.Context;  
  5. import android.content.Intent;  
  6. import android.database.Cursor;  
  7. import android.os.Bundle;  
  8. import android.view.View;  
  9. import android.widget.Button;  
  10. import android.widget.EditText;  
  11. import android.database.sqlite.SQLiteDatabase;  
  12. import android.widget.TextView;  
  13. import android.widget.Toast;  
  14.    
  15. public class Cview extends Activity {  
  16.     EditText cidv;  
  17.     Button bview;  
  18.     Button bac;  
  19.     Button backvc;  
  20.     SQLiteDatabase db;  
  21.     @Override  
  22.     protected void onCreate(Bundle savedInstanceState) {  
  23.         super.onCreate(savedInstanceState);  
  24.         setContentView(R.layout.cview_layout);  
  25.         final Context context=this;  
  26.    
  27.         bview=(Button)findViewById(R.id.bview);  
  28.         cidv=(EditText)findViewById(R.id.cidv);  
  29.         bac=(Button)findViewById(R.id.backcview);  
  30.         backvc=(Button)findViewById(R.id.backvc);  
  31.    
  32.         bview.setOnClickListener(new View.OnClickListener() {  
  33.             @Override  
  34.             public void onClick(View v) {  
  35.                 String t=cidv.getText().toString();  
  36.                 db=openOrCreateDatabase("Banking1",SQLiteDatabase.CREATE_IF_NECESSARY,null);  
  37.                 Cursor c= db.rawQuery("SELECT * FROM bank where id="+t,null);  
  38.                 c.moveToFirst();  
  39.                 int flag=0;  
  40.                 while(! c.isAfterLast())  
  41.                 {  
  42.                     String t2=c.getString(0);  
  43.                     String t3=c.getString(1);  
  44.                     String t4=c.getString(2);  
  45.                     flag=1;  
  46.                     setContentView(R.layout.cview_layout2);  
  47.                     TextView e=(TextView)findViewById(R.id.lav);  
  48.                     e.setText("Id: "+t2+" Type: "+t3+" Bal: "+t4);  
  49.                     c.moveToNext();  
  50.    
  51.                 }  
  52.                 if(flag==0)  
  53.                 {  
  54.                     cidv.setText("");  
  55.                     Toast.makeText(Cview.this"Invalid ID....."2000).show();  
  56.                     Intent i=new Intent(context,Customer.class);  
  57.                     startActivity(i);  
  58.                     //finish();  
  59.                 }  
  60.             }  
  61.         });  
  62.    
  63.         bac.setOnClickListener(new View.OnClickListener() {  
  64.             @Override  
  65.             public void onClick(View v) {  
  66.                 //finish();  
  67.                 Intent i=new Intent(context,Customer.class);  
  68.                 startActivity(i);  
  69.             }  
  70.         });  
  71.    
  72.         backvc.setOnClickListener(new View.OnClickListener() {  
  73.             @Override  
  74.             public void onClick(View v) {  
  75.                // finish();  
  76.                 Intent i=new Intent(context,Customer.class);  
  77.                 startActivity(i);  
  78.             }  
  79.         });  
  80.    
  81.     }  
Step 13
 
In the end, don't forget to add the names of the new activities to the manifest file, in other words, "AndroidMannifest.xml". Append the following code to this file (already modified for Admin):
  1. <activity android:name=".Customer"  
  2.                  android:label="Customer"/>  
  3. <activity android:name=".Cview"  
  4.           android:label="View"/>  
  5. <activity android:name=".Deposit"  
  6.           android:label="Deposit"/>  
  7. <activity android:name=".Withdraw"  
  8.           android:label="Withdraw"/> 
The output snapshots
 
c6.jpg
 
Clicking on Customer will give you:
 
c7.jpg
 
Clicking on Withdraw will give you:
 
c8.jpg
 
When you will click on Withdraw it will return to the Customer menu. Selecting Deposit this time will give you:
 
c9.jpg
 
When you click on Deposit it will return to the Customer menu. Selecting View this time will give you:
 
c10.jpg
 
Clicking on View will give you:
 
c11.jpg
 
This ends my article. I hope that database connectivity is fully clear to you now.
 
Thank you... Enjoy Coding :)