Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////files is called Addnewstudent ////////////////////////////////////////
- package com.example.lab3;
- import java.util.ArrayList;
- import android.app.Activity;
- import android.content.ContentValues;
- import android.content.Intent;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- private EditText student_idEditText;
- private EditText studentNameEditText;
- private EditText module_nameEditText;
- private EditText student_yearEditText;
- private Button cancelButton;
- private Button saveButton;
- private ArrayList<String> studentdetailsarraylist;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- student_idEditText = (EditText) findViewById(R.id.studentID);
- studentNameEditText = (EditText) findViewById(R.id.studentName);
- module_nameEditText = (EditText) findViewById(R.id.moduleName);
- student_yearEditText = (EditText) findViewById(R.id.studentYear);
- addListenerOnButton();
- }
- private void addListenerOnButton() {
- Log.i("Here", "Before shit");
- saveButton = (Button) findViewById(R.id.button2);
- cancelButton = (Button) findViewById(R.id.button1);
- Log.i("After", "After shit");
- saveButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- Toast.makeText(MainActivity.this,"Save button " +
- "clicked now",
- Toast.LENGTH_SHORT).show();
- Log.i("Before", "Before retrieved");
- // Get the values provided by the user via the UI
- String providedstudentid = student_idEditText.getText().toString();
- String providedstudentname = studentNameEditText.getText().toString();
- String providedstudentyear = student_yearEditText.getText().toString();
- String providedmodulename = module_nameEditText.getText().toString();
- Log.i("Values", "Stringss: " + module_nameEditText.getText().toString());
- // Pass above values to the setter methods
- studentdetails studentdetailsObj = new studentdetails();
- studentdetailsObj.setstudentid(providedstudentid);
- studentdetailsObj.setstudentname(providedstudentname);
- studentdetailsObj.setstudentyear(providedstudentyear);
- studentdetailsObj.setmodulename(providedmodulename);
- DBHelper db = new DBHelper(MainActivity.this);
- db.open();
- db.insertNewUser(providedstudentid, providedstudentname, providedmodulename,
- providedstudentyear);
- db.close();
- }
- });
- cancelButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- Toast.makeText(MainActivity.this,"Cancel button " +
- "clicked now",
- Toast.LENGTH_SHORT).show();
- /* End thingy */
- finish();
- }
- });
- }
- public void insertstudent(){
- studentdetails sd = new studentdetails();
- DBHelper db = new DBHelper(MainActivity.this);
- db.open();
- db.insertNewUser(sd.getstudentid(),
- sd.getstudentname(), sd.getmodulename(),
- sd.getstudentyear());
- // I am not going to do the retrieve part in this post. So this is just a notification for satisfaction ;-)
- Toast.makeText(this, "Values inserted", Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement