I\'m having some issues implementing a TimePicker in my application that allows the user to change the time of a database record prior to inserting it.
The problem is th
Please use the below code it is working fine for me.
final TimePicker tp=(TimePicker)findViewById(R.id.timePicker1);
View amPmView = ((ViewGroup)tp.getChildAt(0)).getChildAt(2);
if(amPmView instanceof Button)
{
amPmView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("OnClickListener", "OnClickListener called");
if(v instanceof Button)
{
if(((Button) v).getText().equals("AM"))
{
((Button) v).setText("PM");
if (tp.getCurrentHour() < 12) {
tp.setCurrentHour(tp.getCurrentHour() + 12);
}
}
else{
((Button) v).setText("AM");
if (tp.getCurrentHour() >= 12) {
tp.setCurrentHour(tp.getCurrentHour() - 12);
}
}
}
}
});
}