当我单击应用中的文本时,此TextView上的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();
                    }
                }
            };
        }
    }
);

===============>>#1 票数:1 已采纳

就像注释中提到的@PPartisan一样,您实际上并未将TextView设置为可点击的功能,因为您是在按钮内设置功能。 因此,在您的情况下,应为:

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();
    }
);

  ask by Emanuel Sobreiro translate from so

未解决问题?本站智能推荐: