Professional Documents
Culture Documents
Riffaqat Lab 2
Riffaqat Lab 2
Lab # 2
Submitted by
RIFFAQAT HUSSAIN
Submitted to
Department of BSIT-Morning
6th Semester
Page 1 of 6
Tasks:
Xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:gravity="center_horizontal">
<Button
android:id="@+id/button_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Count"
android:layout_marginBottom="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="560dp"
android:orientation="horizontal"
android:gravity="center_horizontal">
<TextView
android:id="@+id/textView_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="48sp"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_marginEnd="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="@+id/button_toast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Toast"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp" />
</LinearLayout>
</LinearLayout>
Page 2 of 6
Java code:
package com.example.lab2;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showToast();
}
});
buttonCount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
count++;
displayCount();
}
});
}
Page 3 of 6
screenshots:
Page 4 of 6
Lab assignment
Change layout :
Xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="300dp"
android:orientation="vertical"
android:gravity="start">
<Button
android:id="@+id/button_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:layout_marginTop="20dp" />
<Button
android:id="@+id/button_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="160dp"
android:text="Count" />
</LinearLayout>
<TextView
android:id="@+id/textView_count"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:text="0"
android:textSize="48sp"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_marginStart="8dp" />
</LinearLayout>
Page 5 of 6
Screenshot
Page 6 of 6