Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 KB | None | 0 0
  1. ////////////files is called Addnewstudent ////////////////////////////////////////
  2.  
  3. package com.example.lab3;
  4.  
  5. import java.util.ArrayList;
  6.  
  7. import android.app.Activity;
  8. import android.content.ContentValues;
  9. import android.content.Intent;
  10. import android.database.sqlite.SQLiteDatabase;
  11. import android.os.Bundle;
  12. import android.util.Log;
  13. import android.view.View;
  14. import android.view.View.OnClickListener;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17. import android.widget.ImageButton;
  18. import android.widget.Toast;
  19.  
  20. public class MainActivity extends Activity {
  21.  
  22.    
  23.     private EditText student_idEditText;
  24.     private EditText studentNameEditText;
  25.     private EditText module_nameEditText;
  26.     private EditText student_yearEditText;
  27.     private Button cancelButton;
  28.     private Button saveButton;
  29.  
  30.     private ArrayList<String> studentdetailsarraylist;
  31.    
  32.     @Override
  33.     protected void onCreate(Bundle savedInstanceState) {
  34.         super.onCreate(savedInstanceState);
  35.         setContentView(R.layout.activity_main);
  36.    
  37.  
  38.         student_idEditText = (EditText) findViewById(R.id.studentID);
  39.         studentNameEditText = (EditText) findViewById(R.id.studentName);
  40.         module_nameEditText = (EditText) findViewById(R.id.moduleName);
  41.         student_yearEditText = (EditText) findViewById(R.id.studentYear);
  42.        
  43.         addListenerOnButton();
  44.     }
  45.    
  46.     private void addListenerOnButton() {
  47.         Log.i("Here", "Before shit");
  48.         saveButton = (Button) findViewById(R.id.button2);
  49.         cancelButton = (Button) findViewById(R.id.button1);
  50.         Log.i("After", "After shit");
  51.        
  52.         saveButton.setOnClickListener(new OnClickListener() {
  53.         @Override
  54.         public void onClick(View view) {
  55.            
  56.             Toast.makeText(MainActivity.this,"Save button " +
  57.                     "clicked now",
  58.                     Toast.LENGTH_SHORT).show();
  59.            
  60.             Log.i("Before", "Before retrieved");
  61.             // Get the values provided by the user via the UI
  62.             String providedstudentid = student_idEditText.getText().toString();
  63.             String providedstudentname = studentNameEditText.getText().toString();
  64.             String providedstudentyear = student_yearEditText.getText().toString();
  65.             String providedmodulename = module_nameEditText.getText().toString();
  66.             Log.i("Values", "Stringss: " + module_nameEditText.getText().toString());
  67.  
  68.             // Pass above values to the setter methods
  69.             studentdetails studentdetailsObj = new studentdetails();
  70.             studentdetailsObj.setstudentid(providedstudentid);
  71.             studentdetailsObj.setstudentname(providedstudentname);
  72.             studentdetailsObj.setstudentyear(providedstudentyear);
  73.             studentdetailsObj.setmodulename(providedmodulename);
  74.            
  75.             DBHelper db = new DBHelper(MainActivity.this);
  76.             db.open();
  77.             db.insertNewUser(providedstudentid, providedstudentname, providedmodulename,
  78.                     providedstudentyear);
  79.             db.close();
  80.  
  81.             }
  82.         });
  83.        
  84.         cancelButton.setOnClickListener(new OnClickListener() {
  85.             @Override
  86.             public void onClick(View view) {
  87.                
  88.                 Toast.makeText(MainActivity.this,"Cancel button " +
  89.                         "clicked now",
  90.                         Toast.LENGTH_SHORT).show();
  91.                
  92.                 /* End thingy */
  93.                 finish();
  94.                 }
  95.             });
  96.     }
  97.    
  98.     public void insertstudent(){
  99.        
  100.         studentdetails sd = new studentdetails();
  101.         DBHelper db = new DBHelper(MainActivity.this);
  102.         db.open();
  103.         db.insertNewUser(sd.getstudentid(),
  104.                 sd.getstudentname(), sd.getmodulename(),
  105.                 sd.getstudentyear());
  106.  
  107.         // I am not going to do the retrieve part in this post. So this is just a notification for satisfaction ;-)
  108.         Toast.makeText(this, "Values inserted", Toast.LENGTH_SHORT).show();
  109.  
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement