Use this Class
public class TimeListener implements OnClickListener, OnTimeSetListener {
private int hour;
private int minute;
private Activity activity;
private View touchedView;
public TimeListener(Activity activity) {
this.activity = activity;
final Calendar c = Calendar.getInstance();
this.hour = c.get(Calendar.HOUR_OF_DAY);
this.minute = c.get(Calendar.MINUTE);
}
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
@Override
public void onClick(View v) {
touchedView = v;
new TimePickerDialog(activity,
this, this.getHour(), this.getMinute(), false).show();
}
private void updateDisplay() {
((TextView) touchedView).setText(
new StringBuilder()
.append(pad(hour)).append(":")
.append(pad(minute)));
}
private static String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else
return "0" + String.valueOf(c);
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
this.hour = hourOfDay;
this.minute = minute;
updateDisplay();
}
}
and use below code Inside your Activity Class...
private TimeListener timeListener = new TimeListener(this);
view.setOnClicklistner(timeListener);
Thank you...