pr15
pr15
: 2215770083
X. Exercise
Program (activity_main.xml) –
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Hello
World, Toast Example" android:textColor="#000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.047"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.022" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content
"
android:layout_height="wrap_conten
t"
android:layout_marginTop="12dp"
android:text="Show Toast"
app:layout_constraintEnd_toEndOf="
parent"
app:layout_constraintHorizontal_bias=
"0.034"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf
="@+id/textView3" />
</androidx.constraintlayout.widget.ConstraintLayout>
Program (custom_layout.xml) –
version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<CheckBox android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="84dp"
android:text="Pizza"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="168dp"
android:text="Coffee"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="256dp"
android:text="Burger"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498
"
app:layout_constraintStart_toStartOf="parent
"
app:layout_constraintTop_toTopOf="parent"
/>
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="368dp"
android:text="Order"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e3e3e3" android:id="@+id/root_id">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="wrap_cont
ent"
tools:layout_editor_absoluteY="wrap_cont
ent" android:maxLines="6"
android:textColor="#000"/>
</androidx.constraintlayout.widget.ConstraintLayout>
com.example.androidapplication_pat15_2; import
androidx.appcompat.app.AppCompatActivity; import
android.os.Bundle; import
android.view.LayoutInflater; import
android.widget.CheckBox; import
android.widget.TextView; import
android.widget.Toast;
Button btn;
total = 0;
@Override protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.button); c1
= findViewById(R.id.checkBox); c2
= findViewById(R.id.checkBox2);
c3 =
findViewById(R.id.checkBox3);
btn.setOnClickListener(new View.OnClickListener() {
Integer.parseInt(amount[0]);
Integer.parseInt(amount[1]);
Integer.parseInt(amount[2]);
txt.setText(bill);
tst.setDuration(Toast.LENGTH_LONG); tst.setView(layout);
tst.show();
total = 0;
});
}
Output –