Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java TextView OnCLICKCListener似乎无法工作_Java_Android - Fatal编程技术网

Java TextView OnCLICKCListener似乎无法工作

Java TextView OnCLICKCListener似乎无法工作,java,android,Java,Android,当我单击应用程序中的文本时,此文本视图上的onClickListener似乎不起作用。它不显示TimePickerDialog或任何内容。我应该使用TouchListener吗?有什么问题吗?伊曼纽尔,请先帮我谢谢你 代码如下: hora_text.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { hora_button.setOnClickListener(

当我单击应用程序中的文本时,此文本视图上的onClickListener似乎不起作用。它不显示TimePickerDialog或任何内容。我应该使用TouchListener吗?有什么问题吗?伊曼纽尔,请先帮我谢谢你

代码如下:

hora_text.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) { 
        hora_button.setOnClickListener(
            new Button.OnClickListener() {
                public void onClick (View v){
                    Calendar cal = Calendar.getInstance();
                    int hora = cal.get(Calendar.HOUR);
                    int minutos = cal.get(Calendar.MINUTE);
                    TimePickerDialog mTimePicker = new TimePickerDialog(getActivity(),TimePickerDialog.THEME_HOLO_LIGHT,hourSetListener,hora,minutos,true);
                    mTimePicker.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    mTimePicker.show();
                 }
             });

         hourSetListener = new TimePickerDialog.OnTimeSetListener() {
             @Override
             public void onTimeSet(TimePicker timePicker, int hora, int minutos) {
                 hora_text.setText(hora+":"+minutos);
             }
         };
    }
});

date_text.setOnClickListener(
    new View.OnClickListener() {
        public void onClick(View v) {
            date_button.setOnClickListener(
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            Calendar cal = Calendar.getInstance();
                            int year = cal.get(Calendar.YEAR);
                            int month = cal.get(Calendar.MONTH);
                            int day = cal.get(Calendar.DAY_OF_MONTH);
                            DatePickerDialog date_dialog = new DatePickerDialog(getActivity(),                            
                                           android.R.style.Theme_Holo_Light_Dialog_MinWidth,
                                           dateSetListener,
                                            year, month, day);
                            date_dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                            date_dialog.show();
                        };
                    }
            );

            dateSetListener = new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                    month=month + 1;
                    String dt = day + "-" + month + "-" + year;
                    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
                    try {
                        sdf.parse(dt);
                        date_text.setText(dt);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            };
        }
    }
);

就像在评论中提到的@PPartisan一样,您并没有真正设置TextView clickable with功能,因为您是在按钮中设置功能。因此,在您的情况下,应该是:

hora_text.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) { 
        Calendar cal = Calendar.getInstance();
        int hora = cal.get(Calendar.HOUR);
        int minutos = cal.get(Calendar.MINUTE);
        TimePickerDialog mTimePicker = new TimePickerDialog(getActivity(),TimePickerDialog.THEME_HOLO_LIGHT,hourSetListener,hora,minutos,true);
        mTimePicker.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mTimePicker.show();
    }
);

您在文本视图的单击侦听器中所做的一切就是将侦听器分配给按钮。查看您发布的代码,如果您按文本视图
hora_text
,然后按
hora_按钮
,您可能会看到计时器出现。