//android program Database connectivity
Xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t1"
android:text=" "/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="SUBMIT"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b2"
android:text="GET RECORD"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/l1"
android:text="list"/>
</LinearLayout>
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity implements
[Link] {
Button b1, b2;
EditText t1;
TextView l1;
SQLiteDatabase md;
ContentValues values;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link]);
b1 = (Button) findViewById([Link].b1);
b2 = (Button) findViewById([Link].b2);
t1 = (EditText) findViewById([Link].t1);
l1 = (TextView) findViewById([Link].l1);
[Link](this);
[Link](this);
md = openOrCreateDatabase("mydb", MODE_PRIVATE, null);
[Link]("create table student10(name Text)");
values=new ContentValues();
public void onClick(View v) {
try {
if ([Link]() == [Link].b1)
[Link]("name",[Link]().toString());
[Link]("student10",null,values);
[Link](this, "record inserted", Toast.LENGTH_LONG).show();
}
if ([Link]() == [Link].b2) {
Cursor c = [Link]("SELECT * FROM student10",null);
while([Link]()) {
String name = [Link](0);
[Link]("\n" + name);
}
}
}
catch (Exception e)
{
[Link](this, [Link](), Toast.LENGTH_LONG).show();
}
}
}