0% found this document useful (0 votes)
16 views2 pages

Enable Activity - Main Time Simple

The document contains an XML layout and Java code for an Android application activity named MainActivity. It includes a TimePicker that allows users to select a time, which is then displayed in a TextView. The application uses edge-to-edge display and shows a toast message with the selected time when the time is changed.

Uploaded by

Kolekar Yashraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Enable Activity - Main Time Simple

The document contains an XML layout and Java code for an Android application activity named MainActivity. It includes a TimePicker that allows users to select a time, which is then displayed in a TextView. The application uses edge-to-edge display and shows a toast message with the selected time when the time is changed.

Uploaded by

Kolekar Yashraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

XML File androidx.appcompat.app.

AppCompatActivity;
import androidx.core.graphics.Insets;
<?xml version="1.0" encoding="utf-8"?>
import androidx.core.view.ViewCompat;
<RelativeLayout
import
xmlns:android="http://schemas.android.com/
androidx.core.view.WindowInsetsCompat;
apk/res/android"
public class MainActivity extends
xmlns:app="http://schemas.android.com/apk/
AppCompatActivity {
res-auto"
TextView time;
TimePicker simple;
xmlns:tools="http://schemas.android.com/too
ls"
@Override
android:id="@+id/main"
protected void onCreate(Bundle
android:layout_width="match_parent"
savedInstanceState) {
android:layout_height="match_parent"
super.onCreate(savedInstanceState);
tools:context=".MainActivity">
EdgeToEdge.enable(this);
<TimePicker
setContentView(R.layout.activity_main);
android:id="@+id/simple"
time=findViewById(R.id.time);
android:layout_width="wrap_content"
simple=findViewById(R.id.simple);
android:layout_height="wrap_content"
simple.setIs24HourView(false);
android:layout_centerHorizontal="true"
simple.setOnTimeChangedListener(new
android:layout_marginTop="120dp"
TimePicker.OnTimeChangedListener() {
android:timePickerMode="spinner"/>
@Override
public void onTimeChanged(TimePicker
<TextView
view, int hourOfDay, int minute) {
android:id="@+id/time"
int hourOfday = 0;
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Toast.makeText(getApplicationContext(),hour
android:text="Time is ="
Ofday+" "+minute,
android:layout_marginTop="100dp"
Toast.LENGTH_SHORT).show();
android:textSize="20dp"
time.setText("Time
android:layout_marginLeft="100dp"
is:"+hourOfDay+":"+minute);
/>
}
});

</RelativeLayout>

Activity File }
}
package com.technifysoft.prac15;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;

import androidx.activity.EdgeToEdge;
import
OUTPUT

You might also like