Android Program – Time Picker Activity

ANDROID FOR FRESHERS

Android Program Time Picker Activity

Java Code(TimeAct)

import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TimePicker;
import android.widget.Toast;

public class TimeAct extends Activity {
static final int Dialog1 = 1;
int hour,min,second;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time);
}

public void next(View v)
{
showDialog(Dialog1);
}
@Override
protected Dialog onCreateDialog(int id) {

{
return new TimePickerDialog(TimeAct.this,listener2,hour,min,true);

}

}
private TimePickerDialog.OnTimeSetListener listener2 = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
hour = hourOfDay;
min = minute;
second=(hour/3600)+(min/60);
String time=hour+”:”+min;
Toast.makeText(TimeAct.this,time, Toast.LENGTH_SHORT).show();

}
};

}

Layout XML Code(activity_time)

<?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:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.andro.tech.androidproject.TimeAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:layout_gravity=”center”
android:textStyle=”bold”
android:text=”@string/timetext”
android:layout_marginBottom=”120dp” />

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”SET TIME”
android:onClick=”next”
android:layout_marginBottom=”150dp”/>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>

Output

Android Time picker java snippet code download    Android Time picker java snippet code download

Android Time picker java snippet code download

Download Time Picker Source Code

For More Android Programs –Click Here

 

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 

 

Related Search

Android Time picker java snippet code download, Time picker java code snippet, android code time picker source code, android time picker source code download, time picker snippet code, android time picker snippet code download, time picker source code download, android code for time picker java code download

Comments

Vivo Y18 and Y18e launched in India starting at ₹7,999: Review vivo V30e launched in India starting at ₹27999: Full Specs & features HMD Launches Nokia 215, 225, & 235 4G Phone: Full Specs and Pricing Apple 2024 iPad Pro: Premier OLED Panels & M4 Chip, Debuting May 7 6 Best PC Games like Fall Guys in 2024