カレンダーボタンをクリックするたびにピッカーを呼び出そうとしているカスタムカレンダーを作成しましたが、正しく機能しないアプリケーションコードが次にあります。では、このコードを変更して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);
}
}
何していますか?エラーメッセージ/例外はありますか? Plsにはカレンダーボタンのアクションコードが含まれています。 – lupz
私は質問を更新しました。 @ lupz –
ああ、申し訳ありません!私はあなたが最初の視点で間違っていると思う。しかし、私はまだ混乱しています...私がコードを理解する限り、(スクリーンショットに示されているように)毎月のボタンがあります。だからあなたは、日付を選択した後に日付ピッカーを表示したい(1日のボタンを選択/タッチ)?選択した日/日付をすぐに設定/使用できませんでしたか?とにかく、実際にピッカーを表示するためのアクションコードが不足している可能性があります。少なくとも[codenameOne Picker javadoc-example](https://www.codenameone.com/javadoc/com/codename1/ui/spinner/Picker.html)では、ピッカーをフォームに追加し、 'show()'を呼び出します。その上に。 – lupz