Full tutorial is given below. Dear Viewer we are working hard to maintain this website. We doesn't want any think from you. Its just a humble request If you thinks that this posts helps you please share this post with your friends.
Time Picker Dialog - Android Studio
activity_main.xml
<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:padding="10dp" tools:context=".MainActivity" > <Button android:id="@+id/btnPickTime" android:text="Pick Time" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/tvdtime" android:text="Picked Time will show here..." android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
MainActivity.java
package com.usmtip.myapplication; import android.app.TimePickerDialog; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.TimePicker; import androidx.appcompat.app.AppCompatActivity; import java.util.Calendar; public class MainActivity extends AppCompatActivity { Calendar mClndr; TimePickerDialog tpd; Button mBtnPickTime; TextView mTvTime; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTvTime = findViewById(R.id.tvdtime); mBtnPickTime = findViewById(R.id.btnPickTime); mBtnPickTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mClndr = Calendar.getInstance(); int hour = mClndr.get(Calendar.HOUR_OF_DAY); int mint = mClndr.get(Calendar.MINUTE); tpd = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int mhour, int mMint) { mTvTime.setText(mhour + ":" + mMint); } }, hour, mint, false); tpd.show(); } }); } }
0 Comments: