Practical 15,16 MAD
Practical 15,16 MAD
Practical 15,16 MAD
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World Toast Example"
android:textSize="18dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:onClick="showToast"/>
</LinearLayout>
Java code
package com.example.toastmsg;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1=(Button) findViewById(R.id.btn1);
}
public void showToast(View v){
Toast.makeText(this, "Message fo you:\nYou have a new Mail!!",
Toast.LENGTH_LONG).show();
}
}
q.2
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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_x="6dp"
android:layout_y="15dp"
android:text="Coffee"
android:paddingLeft="5dp"
android:textSize="17dp"/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="6dp"
android:layout_y="77dp"
android:text="Pizza"
android:paddingLeft="5dp"
android:textSize="17dp"/>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="5dp"
android:layout_y="152dp"
android:text="Burger"
android:paddingLeft="5dp"
android:textSize="17dp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="148dp"
android:layout_y="232dp"
android:text="Order"
android:textSize="25dp"
android:onClick="showorder"
/>
</AbsoluteLayout>
Java code
package com.example.toastmessage2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
}
}
}
Practical no.16
package com.example.activitylifecycle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("LifeCycle","Activity Created");
Toast.makeText(this, "On create called", Toast.LENGTH_SHORT).show();
}
protected void onStart(){
super.onStart();
Log.d("LifeCycle","Activity Created");
Toast.makeText(this, "On Create Called", Toast.LENGTH_SHORT).show();
}
protected void onResume(){
super.onResume();
Log.d("LifeCycle","Activity Created");
Toast.makeText(this, "On Resume Called", Toast.LENGTH_SHORT).show();
}
protected void onPause(){
super.onPause();
Log.d("LifeCycle","Activity Created");
Toast.makeText(this, "On Pause Called", Toast.LENGTH_SHORT).show();
}
protected void onStop(){
super.onStop();
Log.d("LifeCycle","Activity Created");
Toast.makeText(this, "On Stop Called", Toast.LENGTH_SHORT).show();
}
protected void onDestroy(){
super.onDestroy();
Log.d("LifeCycle","Activity Created");
Toast.makeText(this, "On Destroy Called", Toast.LENGTH_SHORT).show();
}
}