Using timepicker to set time

前端 未结 3 1630
野趣味
野趣味 2021-01-29 00:50

There are two edit text ::

\"enter

Onclick of edittext timepicker

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 01:35

    We can do it smriti3 ,Please try my below sample code and let me know if you found any issues,

         
    

    And Add this sample code in within Activity

        Calendar mcurrentDate=Calendar.getInstance();
            int mHour=mcurrentDate.get(Calendar.HOUR_OF_DAY);
            int mMinute=mcurrentDate.get(Calendar.MINUTE);
            EditText mAddTime=(EditText)findViewById(R.id.add_TimePicker);    
            mAddTime.setOnClickListener(new OnClickListener() {
    
                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub          
    
                            TimePickerDialog mTimePicker=new TimePickerDialog(AddNewMessage.this, new OnTimeSetListener() {                 
                                public void onTimeSet(TimePicker timepicker, int selectedhour, int selectedminute) {
                                    // TODO Auto-generated method stub  
    
                                 mAddTime.setText(selectedhour+":"+selectedminute);
    
                                }
                            },mHour, mMinute,true);
                            mTimePicker.setTitle("Set Time");
                            mTimePicker.show();   
        }
       });
    

提交回复
热议问题