Posts

Showing posts from January, 2015

Custom Timer Example in Android

Image
Hello Friends,. Today I am going to share important code for countdown watch in Android. For this I am using Handler Thread. Hope it will help you guys. Just copy paste below code and enjoy. 1. TimerActivity.java package com.pack.counttimer; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; import android.view.View; import android.widget.Button; import android.widget.TextView; public class TimerActivity extends Activity { private TextView textTimer; private Button startButton; private Button pauseButton; private long startTime = 0L; private Handler myHandler = new Handler(); long timeInMillies = 0L; long timeSwap = 0L; long finalTime = 0L; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_timer); textTimer = (TextView) findViewById(R.id.textTimer); startButton =

Date Picker in Android

Image
Hello Guys !! Here is the simple example of Date Picker in Android.. 1. DatePickerActivity.java package com.pack.datepicker; import java.util.Calendar; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.DatePicker; import android.widget.TextView; public class DatePickerActivity extends Activity { TextView textDate; private int year; private int month; private int day; static final int DATE_DIALOG_ID = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_date_picker); textDate = (TextView) findViewById(R.id.text_date); final Calendar c = Calendar.getInstance(); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); day = c.get(Calendar.DAY_OF_MONTH); textDate.setOnClickListener(new OnCl

Time Picker in Android

Image
Hello Guys !! In Android it’s very easy to set the time using the  android.widget.TimePicker component. In this tutorial we are going to see how the user can select the hour, and the minute using the  android.app.TimePickerDialog  which is an easy to use dialog box. Android comes equipped with a widget named TimePicker which we can integrate in our  application  to provide this functionality to the end users. It has an elegant look and design. So, lets get started.. 1.  TimePickerActivity.java package com.example.timepicker; import java.util.Calendar; import android.app.Activity; import android.app.Dialog; import android.app.TimePickerDialog; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.ImageButton; import android.widget.TimePicker; public class TimePickerActivity extends Activity implements OnClickListener { private ImageButton mImgBT; private Calendar c