Android database (p3)- INSERT record example

This tutorial is continuation of part 2 –> http://blog.kerul.net/2013/08/android-database-p2-search-example.html

Add a new Activity to the existing project. This Activity is named InsertActivity. The UI is as in the following screenshot.

insert-record-sqlite-android

The UI xml. – available in the sourcecode –>  https://docs.google.com/file/d/0B34ZxOOoeSDdQ3VkWVdaZE43eDg/edit?usp=sharing

While onClick of the button, the program will fetch the Malay word, and the English pair provided by the user.

public void onClick(View arg0) {
// TODO Auto-generated method stub
String wmelayu=txtmelayu.getText().toString();
String wenglish=txtenglish.getText().toString();
//kena letak dalam onclick
//-run SELECT command to fetch data from table
String sql;
sql="INSERT INTO melayuenglish (katamelayu, kataeng) VALUES ('"+wmelayu+"','"+wenglish+"');";
db.execSQL(sql);
String msg="Perkataan baru disimpan, "+sql;
Toast.makeText(getApplicationContext(), msg,Toast.LENGTH_SHORT).show();
}

 

insert-record-sqlite-android-confirmed

 

Download the complete Source-code here - https://docs.google.com/file/d/0B34ZxOOoeSDdQ3VkWVdaZE43eDg/edit?usp=sharing

Popular Posts

WorldConferences.net