Practical 15
Q1.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Practical 15 - Toast"
android:textStyle="bold"
android:layout_marginBottom="20dp"
android:textSize="20sp"/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Content" />
</LinearLayout>
</[Link]>
[Link]
package [Link].prc15;
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 showToastButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link], "Message for you: You have got mail!",
Toast.LENGTH_LONG).show();
}
});
}
}
Q2.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Pizza" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Dal Bhatti" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Civet Coffee" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order"
android:layout_marginTop="20dp" />
</LinearLayout>
</[Link]>
[Link]
package [Link].prc15;
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);
CheckBox pizzaCheckBox = findViewById([Link]);
CheckBox coffeeCheckBox = findViewById([Link].checkBox2);
CheckBox burgerCheckBox = findViewById([Link].checkBox3);
Button orderButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
StringBuilder orderSummary = new StringBuilder("Selected Items:\n");
int total = 0;
if ([Link]()) {
[Link]("Pizza: ₹300\n");
total += 300;
}
if ([Link]()) {
[Link]("Dal Bhatti: ₹200\n");
total += 200;
}
if ([Link]()) {
[Link]("Civer Coffee: ₹300\n");
total += 300;
}
[Link]("Total: ").append(total).append("₹");
[Link]([Link], [Link](),
Toast.LENGTH_LONG).show();
}
});
}
}