Nikhil Android
Nikhil Android
Course : [Link].I.T.
Div :A
Roll No. : 12
Subject : Advanced Mobile Programming
Year : 2025 - 2026
UNIVERSITY OF MUMBAI
SHETH T.J EDUCATION SOCIETY’S,
SHETH N.K.T.T. COLLEGE OF
COMMERCE & SHETH J.T.T. COLLEGE
OF ARTS, THANE (W)
(AUTONOMOUS)
CERTIFICATE
Place : THANE
Date :
Activity_Main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Nikhil!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
[Link]
package [Link].practical1_helloworld;
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
Output :
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/xyz"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Nikhil"
android:textSize="50dp"
android:textStyle="bold"
android:textColor="@color/Nikhil_Green"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
Main_Activity.java
package [Link].a2_resources;
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
[Link]
<resources>
<string name="app_name">2_Resources</string>
<string name="Nikhil">
<item>Hello</item>
<item>Nikhil</item>
</string>
</resources>
[Link]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="Nikhil_Blue">#03A9F4</color>
<color name="Nikhil_Green">#00FF55</color>
</resources>
[Link]
<resources xmlns:tools="[Link]
<!-- Base application theme. -->
<style name="[Link].2_Resources"
parent="[Link]">
<!-- Customize your light theme here. -->
<item name="colorPrimary">#8000FF</item>
</style>
<style name="Theme.2_Resources" parent="[Link].2_Resources" />
</resources>
Output:
Activty_Main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
[Link]
package [Link].a3_emptyviewsactivity;
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
String tag = "Activity Life Cycle ";
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Log.d(tag,"On Create Method");
}
@Override
protected void onStart() {
[Link]();
Log.d(tag,"On Start Method");
}
@Override
protected void onRestart() {
[Link]();
Log.d(tag,"On Restart Method");
}
@Override
protected void onPause() {
[Link]();
Log.d(tag,"On Pause Method");
Log.i(tag,"Test");
}
@Override
protected void onResume() {
[Link]();
Log.d(tag,"On Resume Method");
}
@Override
protected void onStop() {
[Link]();
Log.d(tag,"On Stop Method");
}
@Override
protected void onDestroy() {
[Link]();
Log.d(tag,"On Destroy Method");
}
}
Output:
Main_Activity.java :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private Button btnClick;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btnClick = (Button) findViewById([Link].btn1);
[Link](new [Link]() {
public void onClick(View view)
{
[Link](getApplicationContext(), "Button 1 CLicked", Toast.LENGTH_SHORT).show();
}
});
btnClick = (Button) findViewById([Link].btn2);
[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "Button 2 CLicked", Toast.LENGTH_SHORT).show();
}
});
}
}
Output :
4b)_ RelativeLayout
Activity_main.xml :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="30dp"
android:text="Relative Layout" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
</RelativeLayout>
Main_Activity.java :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
Output :
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />
<Button
android:id="@+id/btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />
<Button
android:id="@+id/btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
</TableRow>
</TableLayout>
</LinearLayout>
Main_Activity.java :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
});
Output :
4d)_ FrameLayout
Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50sp"
android:textAlignment="center"
android:text="Frame Layout" />
<ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:src="@drawable/x" > </ImageView>
</FrameLayout>
Main_Activity.java :
package [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
Output :
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:id="@+id/btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />
SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)
Advanced Mobile Programming
<Button
android:id="@+id/btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />
<Button
android:id="@+id/btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
</GridLayout>
Main_Activity.java :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
btnClick = findViewById([Link].btn1);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 1 clicked");
}
});
btnClick = findViewById([Link].btn2);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 2 clicked");
}
});
btnClick = findViewById([Link].btn3);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 3 clicked");
}
SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)
Advanced Mobile Programming
});
btnClick = findViewById([Link].btn4);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 4 clicked");
}
});
btnClick = findViewById([Link].btn5);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 5 clicked");
}
});
btnClick = findViewById([Link].btn6);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 6 clicked");
}
});
btnClick = findViewById([Link].btn7);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 7 clicked");
}
});
btnClick = findViewById([Link].btn8);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 8 clicked");
}
});
btnClick = findViewById([Link].btn9);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 9 clicked");
}
});
}
Output :
PRACTICAL 5
ProjectName -> App -> Src -> Main -> Res -> values-> [Link] The default line is: <style
name="Theme.Practical5" parent="[Link]"> Change to:
[Link]
<resources xmlns:tools="[Link]
<!-- Base application theme. -->
<style name="[Link]"
parent="[Link]">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>
Activity_main.xml
</RelativeLayout>
[Link]
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="cursive"
android:text="Practical 5"
android:textSize="29dp"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:text="LogOut" />
</[Link]>
Main_Activity.java
package [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Output:
Activity_main.xml
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAlignment="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Practical 5 : UI Components"
android:textSize="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculator"
android:layout_gravity="center"
android:textSize="30dp" />
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Number 1"
android:inputType="number" />
<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Number 2"
android:inputType="number"
/>
<Button
android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Addition" />
<Button
android:id="@+id/btnSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtraction" />
<Button
android:id="@+id/btnMult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Multiplication" />
<Button
android:id="@+id/btnDiv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Division" />
<Button
android:id="@+id/btnClear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Clear" />
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Output :"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>
[Link]
package [Link].a5_uicomponents;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
t1 = (EditText) findViewById([Link].et1);
t2 = (EditText) findViewById([Link].et2);
b1 = (Button) findViewById([Link]);
b2 = (Button) findViewById([Link]);
b3 = (Button) findViewById([Link]);
b4 = (Button) findViewById([Link]);
b5 = (Button) findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 + n2;
[Link]("Addition=" + sum);
} catch (NumberFormatException e) {
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 - n2;
[Link]("Subtraction =" + sum);
} catch (NumberFormatException e) {
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 * n2;
[Link]("Multiplication=" + sum);
} catch (NumberFormatException e) {
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 / n2;
[Link]("Division=" + sum);
} catch (NumberFormatException e) {
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]("Output");
}
});
}
}
Output :
5c. Fragments
Activty_main.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="News"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Sports"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:text="Entertainment"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<[Link]
android:id="@+id/fragmentContainerView"
android:name="[Link].a5b_fragments.News"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</[Link]>
</LinearLayout>
</LinearLayout>
Fragment_ent.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EntFragment">
</FrameLayout>
Fragment_news.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".News">
</FrameLayout>
Fragment_sports.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SportsFragment">
</FrameLayout>
[Link]
package [Link].a5b_fragments;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Button btnnews=findViewById([Link].button1);
[Link](new [Link]() {
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getSupportFragmentManager();
[Link]()
.replace([Link], [Link], null)
.setReorderingAllowed(true)
.addToBackStack("name") // Name can be null
.commit();
}
});
Button btnsports=findViewById([Link].button2);
[Link](new [Link]() {
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getSupportFragmentManager();
[Link]()
.replace([Link], [Link], null)
.setReorderingAllowed(true)
.addToBackStack("name") // Name can be null
.commit();
}
});
Button btnent=findViewById([Link].button3);
[Link](new [Link]() {
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getSupportFragmentManager();
[Link]()
.replace([Link], [Link], null)
.setReorderingAllowed(true)
.addToBackStack("name") // Name can be null
.commit();
}
});
}
}
Output:
6. Menus
Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu Bar Demonstration"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
Main_Activity.java :
package [Link].a6_menus;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate([Link],menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch ([Link]()){
case [Link]:
[Link](this,"You have clicked on settings",Toast.LENGTH_SHORT).show();
return true;
case [Link]:
[Link](this,"You have clicked on About Us",Toast.LENGTH_SHORT).show();
return true;
case [Link]:
[Link](this,"You have clicked on Share",Toast.LENGTH_SHORT).show();
return true;
case [Link]:
[Link](this,"You have clicked on Log Out",Toast.LENGTH_SHORT).show();
return true;
default:
return [Link](item);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
Output :
7) Alert Dialog
Activity_main.xml :
Main_Activity.java :
package [Link].a7_alertdialog;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link](false);
[Link]("Yes", ([Link])
(dialog, which) -> {
// When the user click yes button then app will close
finish();
});
[Link]("No", ([Link])
(dialog, which) -> {
// If user click no then dialog box is canceled.
[Link]();
});
Output :
Practical 8
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Name :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText_name"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Surname :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText_surname"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Marks :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText_name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignTop="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:layout_toRightOf="@+id/textView"
android:hint="Enter Your Name" />
<EditText
android:id="@+id/editText_surname"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignTop="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:hint="Enter Your Surname" />
<EditText
android:id="@+id/editText_Marks"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/editText_surname"
android:layout_toEndOf="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:hint="Enter The Marks" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Data"
android:id="@+id/button_add"
android:layout_below="@+id/editText_Marks"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="76dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View All"
android:id="@+id/button_viewAll"
android:layout_above="@+id/button_update"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:id="@+id/button_update"
android:layout_below="@+id/button_add"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/textView_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText_Marks"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="id :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText_id"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignTop="@+id/textView_id"
android:layout_toEndOf="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:hint="Enter ID to Update Or Delete !" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:id="@+id/button_delete"
android:layout_centerVertical="true"
android:layout_below="@+id/button_viewAll"
android:layout_alignLeft="@+id/button_viewAll"
android:layout_alignStart="@+id/button_viewAll" />
</RelativeLayout>
[Link]
package [Link].a8_database;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
DatabaseHelper myDb;
EditText editName,editSurname,editMarks ,editTextId;
Button btnAddData;
Button btnviewAll;
Button btnDelete;
Button btnviewUpdate;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
myDb = new DatabaseHelper(this);
editName = (EditText)findViewById([Link].editText_name);
editSurname = (EditText)findViewById([Link].editText_surname);
editMarks = (EditText)findViewById([Link].editText_Marks);
editTextId = (EditText)findViewById([Link].editText_id);
btnAddData = (Button)findViewById([Link].button_add);
btnviewAll = (Button)findViewById([Link].button_viewAll);
btnviewUpdate= (Button)findViewById([Link].button_update);
btnDelete= (Button)findViewById([Link].button_delete);
AddData();
viewAll();
UpdateData();
DeleteData();
}
public void DeleteData() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
Integer deletedRows = [Link]([Link]().toString());
if(deletedRows > 0)
[Link]([Link],"Data Deleted",Toast.LENGTH_LONG).show();
else
[Link]([Link],"ID Not Found",Toast.LENGTH_LONG).show();
}
}
);
}
public void UpdateData() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
boolean isUpdate = [Link]([Link]().toString(),
[Link]().toString(),
[Link]().toString(),[Link]().toString());
if(isUpdate == true)
[Link]([Link],"Data Updated",Toast.LENGTH_LONG).show();
else
[Link]([Link],"Data not Updated",Toast.LENGTH_LONG).show();
}
}
);
}
public void AddData() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
boolean isInserted = [Link]([Link]().toString(),
[Link]().toString(),
[Link]().toString() );
if(isInserted == true)
[Link]([Link],"Data Inserted",Toast.LENGTH_LONG).show();
else
[Link]([Link],"Data not Inserted",Toast.LENGTH_LONG).show();
}
}
);
}
public void viewAll() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
Cursor res = [Link]();
if([Link]() == 0) {
// show message
showMessage("Error","Nothing found");
return;
}
StringBuffer buffer = new StringBuffer();
while ([Link]()) {
[Link]("Id :"+ [Link](0)+"\n");
[Link]("Name :"+ [Link](1)+"\n");
[Link]("Surname :"+ [Link](2)+"\n");
[Link]("Marks :"+ [Link](3)+"\n\n");
}
// Show all data
showMessage("Data",[Link]());
}
}
);
}
public void showMessage(String title,String Message){
[Link] builder = new [Link](this);
[Link](true);
[Link](title);
[Link](Message);
[Link]();
}
[Link]
package [Link].a8_database;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
[Link]("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
public boolean insertData(String name,String surname,String marks) {
SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();
[Link](COL_2,name);
[Link](COL_3,surname);
[Link](COL_4,marks);
long result = [Link](TABLE_NAME,null ,contentValues);
if(result == -1)
return false;
else
return true;
}
public Cursor getAllData() {
SQLiteDatabase db = [Link]();
Cursor res = [Link]("select * from "+TABLE_NAME,null);
return res;
}
public boolean updateData(String id,String name,String surname,String marks) {
SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();
[Link](COL_1,id);
[Link](COL_2,name);
[Link](COL_3,surname);
[Link](COL_4,marks);
[Link](TABLE_NAME, contentValues, "ID = ?",new String[] { id });
return true;
}
public Integer deleteData (String id) {
SQLiteDatabase db = [Link]();
return [Link](TABLE_NAME, "ID = ?",new String[] {id});
}
}
Output :
Update Data :
Delete Data :