Created
January 14, 2019 16:36
-
-
Save Ibrahim-ullah/a735a2883e4aa4ae0938d05854c614bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.himu.homecontrol; | |
import android.app.TimePickerDialog; | |
import android.content.Context; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TimePicker; | |
import android.widget.Toast; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
public class MainActivity extends AppCompatActivity { | |
EditText LoadTime; | |
Calendar calendar; | |
int currentHour; | |
int currentMinute; | |
TimePickerDialog timePickerDialog; | |
String amPm; | |
Button click; | |
int hour; | |
int min; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
LoadTime = findViewById(R.id.LoadTime); | |
click = findViewById(R.id.click); | |
LoadTime.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
calendar = Calendar.getInstance(); | |
currentHour = calendar.get(Calendar.HOUR_OF_DAY); | |
currentMinute = calendar.get(Calendar.MINUTE); | |
timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() { | |
@Override | |
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minutes) { | |
if (hourOfDay >= 12) { | |
amPm = "PM"; | |
} else { | |
amPm = "AM"; | |
} | |
LoadTime.setText(String.format("%02d:%02d", hourOfDay, minutes) + amPm); | |
} | |
}, currentHour, currentMinute, false); | |
Log.d("INT", "val: " + hour); | |
timePickerDialog.show(); | |
} | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment