Back to project page 2014-Droid-code.
The source code is released under:
GNU General Public License
If you think the Android project 2014-Droid-code listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package cs518.sample.database; /*from w ww .j a va 2 s. c o m*/ import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; /* * AddStudent.class * * This Activity is a UI used simply to add records to the db * * It uses a DBHelper class for the sqlite database */ public class AddStudent extends Activity implements OnClickListener { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); Button btn_submit = (Button)findViewById(R.id.btn_submit); btn_submit.setOnClickListener(this); } public void onClick(View v) { int grade; DBHelper dbh = DBHelper.getDBHelper(this); // get the data from the UI String firstName = ((EditText)findViewById(R.id.et_name)).getText().toString(); String lastName = ((EditText)findViewById(R.id.et_lastName)).getText().toString(); String className = ((EditText)findViewById(R.id.et_class)).getText().toString(); try { grade = Integer.parseInt(((EditText)findViewById(R.id.et_grade)).getText().toString()); } catch (NumberFormatException e) { grade = -1; // not a valid grade } // add the data to the db long code = dbh.insertNewStudent(firstName, lastName, className, grade); if (code != -1) Toast.makeText(this, R.string.insert_ok, Toast.LENGTH_LONG).show(); // finish() means one entry at a time // finish(); } }