gpt4 book ai didi

java - TimePickerDialog 不会显示

转载 作者:行者123 更新时间:2023-12-01 23:11:17 28 4
gpt4 key购买 nike

我正在尝试制作一个简单的TimePickerDialog。当用户单击 editText 框时,时间选择器就会出现。你能帮忙吗?下面的代码不会显示该对话框。感谢您的帮助。

package com.example.myproject;

import java.util.Calendar;

import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;

import android.widget.DatePicker;
public class MainActivity extends Activity {

private OnTimeSetListener myTimePicker;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

public void show(){

Calendar c=Calendar.getInstance();
int Sysday=c.get(Calendar.DAY_OF_MONTH);
int Sysmonth=c.get(Calendar.MONTH);
int Sysyear=c.get(Calendar.YEAR);

int Sysmin=c.get(Calendar.MINUTE);
int Syshour=c.get(Calendar.HOUR);



new TimePickerDialog(this, myTimePicker , Syshour, Sysmin, false);


}



}
<小时/>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="mytext"
android:onClick="show"
/>

</RelativeLayout>

最佳答案

改变

public void show(){

public void show(View v){

还有

new TimePickerDialog(this, myTimePicker , Syshour, Sysmin, false);

(new TimePickerDialog(this, myTimePicker , Syshour, Sysmin, false)).show();

关于java - TimePickerDialog 不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21928582/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com