1

何らかの理由でタイムピッカーから設定された時間を取得しようとしていますが、それは起こっていません。

私は getCurrentHour と getCurrentMinute() を使用していますが、それらは仕事をしていないようです. clearFocus() を試みましたが、違いはありませんでした.

ボタンクリックで時間を取得しようとしています。関連するコードを以下に添付しました。これ以上表示する必要がある場合はお知らせください。

  Button next_button = (Button) findViewById(R.id.next_button);
    next_button.setOnClickListener(new View.OnClickListener() {
       public void onClick(View arg0) { 

           //Calendar current = Calendar.getInstance();
           Calendar cal = Calendar.getInstance(); 

           //time_picker = (TimePicker) findViewById(R.id.time);

          // time_picker.clearFocus(); // this did not help 
            cal.set(
              time_picker.getCurrentHour(), 
              time_picker.getCurrentMinute(), 
              00);

            Toast.makeText(getApplicationContext(), 
                  "set time: "+cal.getTime(), 
                  Toast.LENGTH_LONG).show(); // this is returning the current time
                                                  // that gets initialised with 
             setAlarm(cal);

       }

    });

私の質問は次のとおりです。TImePickerから時間を取得するにはどうすればよいですか?

時間を割いてこれを読んでくれてありがとう。

4

2 に答える 2

1
cal.set(time_picker.getCurrentHour(), time_picker.getCurrentMinute(), 00);

年、月、日の設定に使用されるオーバーロードされたメソッドを呼び出します。

の指定されたフィールドを設定するために使用される double 引数を使用しますsetCalendar

cal.set (Calendar.HOUR_OF_DAY, time_picker.getCurrentHour());
cal.set (Calendar.MINUTE, time_picker.getCurrentMinute());
cal.set (Calendar.SECOND, 0);
cal.set (Calendar.MILLISECOND,0);
于 2013-08-23T18:59:15.020 に答える