2017-04-11 72 views
1

カレンダーボタンをクリックするたびにピッカーを呼び出そうとしているカスタムカレンダーを作成しましたが、正しく機能しないアプリケーションコードが次にあります。では、このコードを変更してActionEventからピッカーを呼び出すことはできますか?コード名の日付ピッカーの問題

public class PivDisplayCalendar extends Container { 


    int length =37; 
    private ComboBox year; 
    private static final String[] DAYS = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 
    private static final String[] LABELS = {"Su", "M", "Tu", "W", "Th", "F", "Sa"}; 

    private ArrayList<Button> allButtons = new ArrayList<Button>(); 
    //Button newButton = new Button(""); 

    public PivDisplayCalendar(){ 

     super(new BoxLayout(BoxLayout.Y_AXIS)); 
      Container calendarTitle = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER)); 
      Container title = new Container(new GridLayout(1,7)); 
      Container days = new Container(new GridLayout(6, 7)); 
      Container calendarTitleCopy = new Container(new GridLayout(1, 1)); 
       calendarTitleCopy.setUIID("CalendarTitleCopy"); 
      this.addComponent(calendarTitleCopy); 
      this.addComponent(title); 
      this.addComponent(days); 


      Button prevMonth = new Button("<"); 
      Button nextMonth = new Button(">"); 
      SpanLabel monthYear = new SpanLabel("Month " + " Year"); 
      calendarTitle.add(BorderLayout.WEST, prevMonth); 
      calendarTitle.add(BorderLayout.CENTER, monthYear); 
      calendarTitle.add(BorderLayout.EAST, nextMonth); 
      calendarTitleCopy.add(calendarTitle); 
      Button dayButton= new Button(); 




      if(UIManager.getInstance().isThemeConstant("calTitleDayStyleBool", false)) { 
       title.setUIID("CalendarTitleArea"); 
       days.setUIID("CalendarDayArea"); 
      } 
      for (int iter = 0; iter < DAYS.length; iter++) { 
       title.addComponent(createDayTitle(iter)); 
      } 
      for (int iter = 1; iter < length; iter++) { 
       dayButton = new Button(""+iter); 

        dayButton.addActionListener(new ActionListener() { 
         @Override 
         public void actionPerformed(ActionEvent evt) { 
          Log.p("Action event triggered"); 
          Picker datePicker = new Picker(); 
          datePicker.setType(Display.PICKER_TYPE_DATE); 

          //Button b1 = (Button)(evt.getActualComponent()); 
          //Log.p(b1.getText()); 
         } 
        }); 

       allButtons.add(dayButton); 
       days.addComponent(dayButton); 
       if (iter <= 7) { 
        dayButton.setNextFocusUp(year); 
       } 
      }    
    } 


    protected Label createDayTitle(int day) { 
     String value = getUIManager().localize("Calendar." + DAYS[day], LABELS[day]); 
     Label dayh = new Label(value, "Label"); 
     dayh.setEndsWith3Points(false); 
     dayh.setTickerEnabled(false); 
     return dayh; 
    } 
} 

これは私のアプリケーションのスクリーンショットです: - :あなたのコードはPickerコンポーネントを作成

for (int iter = 1; iter < length; iter++) { 
       dayButton = new Button(""+iter); 

        dayButton.addActionListener(new ActionListener() { 
         @Override 
         public void actionPerformed(ActionEvent evt) { 
          Log.p("Action event triggered"); 
          Picker datePicker = new Picker(); 
          datePicker.setType(Display.PICKER_TYPE_DATE); 

          //Button b1 = (Button)(evt.getActualComponent()); 
          //Log.p(b1.getText()); 
         } 
        }); 

       allButtons.add(dayButton); 
       days.addComponent(dayButton); 
       if (iter <= 7) { 
        dayButton.setNextFocusUp(year); 
       } 
      } 
+0

何していますか?エラーメッセージ/例外はありますか? Plsにはカレンダーボタンのアクションコードが含まれています。 – lupz

+0

私は質問を更新しました。 @ lupz –

+0

ああ、申し訳ありません!私はあなたが最初の視点で間違っていると思う。しかし、私はまだ混乱しています...私がコードを理解する限り、(スクリーンショットに示されているように)毎月のボタンがあります。だからあなたは、日付を選択した後に日付ピッカーを表示したい(1日のボタンを選択/タッチ)?選択した日/日付をすぐに設定/使用できませんでしたか?とにかく、実際にピッカーを表示するためのアクションコードが不足している可能性があります。少なくとも[codenameOne Picker javadoc-example](https://www.codenameone.com/javadoc/com/codename1/ui/spinner/Picker.html)では、ピッカーをフォームに追加し、 'show()'を呼び出します。その上に。 – lupz

答えて

2

から

enter image description here

及び方法は、イベント処理のために使用され、次の、それをどのような形式にも追加しませんまたはそれを表示する。恐らく、あなたが探しているものはDisplay.showNativePicker()です。これは、単純にネイティブのピッカーダイアログをポップアップするためです。

プラットフォームがネイティブのピッカーをサポートしているかどうかを確認してください(iOSとAndroidのみがネイティブピッカーを持っています)。DateSpinnerコンポーネントを含む独自のダイアログを作成してください。 source for the Picker classをチェックして、これがどのように行われるかの例をご覧ください。

+0

Steveが私を助けてくれてありがとう。そして、私はこのプロジェクトをAndroid用だけでなくIOS向けにやっているので、これは私のプロジェクトにとって理想的なソリューションになるだろう。 @steve hannah –