Practical no 16
Practical no 16
Activity_main.xml
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<DatePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:datePickerMode="spinner"
android:calendarViewShown="false"
android:id="@+id/da"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="selected"/>
</LinearLayout>
MainActivity.java
package com.example.ex161;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1.setOnClickListener(new View.OnClickListener() {
@Override
int y=d1.getYear();
int m=d1.getMonth()+1;
int d=d1.getDayOfMonth();
String s="day-"+d+"\n"+"month"+m+"\n"+"year"+y;
Toast.makeText(MainActivity.this, s, Toast.LENGTH_LONG).show();
});
Output:
Practical no. 16(Timepicker)
Activity_main.xml
<LinearLayout 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:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/time"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bu"
android:text="selected"/>
</LinearLayout>
MainActivity.java
package com.example.ex162;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;
@Override
setContentView(R.layout.activity_main);
TimePicker t1=(TimePicker)findViewById(R.id.time);
button.setOnClickListener(new View.OnClickListener() {
@Override
int t=t1.getHour();
int m=t1.getMinute();
String s="hour-"+t+"\n"+"Minute"+m;
Toast.makeText(MainActivity.this, s, Toast.LENGTH_LONG).show();
});
Output: