如何在加载内容后刷新无限容器。请参阅随附的代码。 我尝试了不同的方法来刷新容器,但是它们都不起作用。我尝试了以下帖子,但无法使其正常工作。 Manually trigger Pull to refresh on Container 如果有人可以指出我应该在哪里更改代码以手动刷新,那就太好了。请让我知道。
class AppointmentsContainerInfinite extends InfiniteContainer {
private final Server.AppointmentFolders folder;
private Date currentDate = new Date();
private Date counterDate = currentDate;
public AppointmentsContainerInfinite(boolean includeAccept, boolean includeReject, boolean includeMap, Server.AppointmentFolders folder) {
this.includeAccept = includeAccept;
this.includeReject = includeReject;
this.includeMap = includeMap;
this.folder = folder;
}
@Override
public Component[] fetchComponents(int index, int amount) {
if (index == 0) {
counterDate = currentDate;
}
SimpleDateFormat sd = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
final int DAY = 24 * 60 * 60000;
Date dd = endDate;
if (endDate == null) {
dd = new Date(System.currentTimeMillis() + DAY * Server.instance.getAppointmentDaysPerBatch());
}
boolean flg = Server.instance.isOffline();
Appointment[] apps = Server.instance.fetchAppointments(counterDate, dd, folder);
ArrayList<Component> response = new ArrayList<>();
String lastDate = sd.format(counterDate);
response.add(new Label(lastDate, "Header"));
if (apps == null || apps.length == 0) {
if (index == 0) {
return new Component[]{new Label("No Appointments", "Header")};
}
return null;
}
for (Appointment app : apps) {
String d = sd.format(app.getDate());
if (!d.equals(lastDate)) {
response.add(new Label("No Appointments", "Header1"));
}
break;
}
for (Appointment a : apps) {
String d = sd.format(a.getDate());
if (!d.equals(lastDate)) {
SimpleDateFormat sd1 = new SimpleDateFormat("MMMM dd,yyyy");
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date startDate1 = SITUtil.removeTime(a.getDate());
Date endDate1 = SITUtil.removeTime(counterDate);
if ((endDate1.getTime() / DAY) + 1 < startDate1.getTime() / DAY) {
// add "No Appointments" enteries until the next date...
Date temp = new Date(endDate1.getTime() + DAY);
while (temp.getTime() / DAY < startDate1.getTime() / DAY) {
response.add(new Label(sd.format(temp), "Header"));
response.add(new Label("No Appointments", "Header1"));
temp = new Date(temp.getTime() + DAY);
}
}
lastDate = d;
counterDate = a.getDate();
response.add(new Label(lastDate, "Header"));
}
// else {
Image icon;
if (a.getEndTime() > -1) {
if (greenIcon == null) {
greenIcon = Image.createImage(iconSize, iconSize, 0xff4caf50);
}
icon = greenIcon;
} else {
Calendar cal = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
cal1.setTime(a.getDate());
yellowIcon = Image.createImage(iconSize, iconSize, ColorUtil.rgb(255, 140, 0));
icon = yellowIcon;
}
}
String endOrDuration;
if (a.getEndTime() > -1) {
endOrDuration = "End: " + SITUtil.formatTime(a.getEndTime());
} else if (Server.instance.isShownField("DurationInMinutesForAppointmentDetailsForMobile")) {
endOrDuration = "Duration: " + a.getDurationMinutes() + " Mins";
} else {
endOrDuration = "Duration: " + SITUtil.formatDuration(a.getDurationMinutes());
}
SmartButton appointmentButton = new SmartButton(a.getAppointmentNumber(),
icon,
"Start: " + SITUtil.formatTime(a.getStartTime()),
endOrDuration);
if (Server.instance.isOffline()) {
Style s = appointmentButton.getRightComponent().getAllStyles();
s.setBgTransparency(255);
s.setBgColor(0xFFFF00);
}
appointmentButton.addActionListener(e -> new AppointmentForm(a, includeAccept, includeReject, includeMap).show());
response.add(appointmentButton);
// }
}
counterDate = new Date(counterDate.getTime() + DAY);
return response.toArray(new Component[response.size()]);
}
}
public AppointmentsForm(boolean includeAccept, boolean includeReject, boolean includeMap, Server.AppointmentFolders folder) {
super(new BorderLayout());
if (Display.getInstance().isTablet()) {
hText = 6.5f;
}
for (MenuOptions m : MenuOptions.values()) {
if ((m.getName().toLowerCase().indexOf(folder.toString().toLowerCase())) >= 0) {
this.setTitle(m.getTitle());
}
}
boolean flg1 = Server.instance.isOffline();
AppointmentsContainerInfinite appointmentsContainer = new AppointmentsContainerInfinite(includeAccept, includeReject, includeMap, folder);
SITUtil.addDateRange(this, (s, e) -> appointmentsContainer.setRange(s, e));
SITUtil.addSideMenu(this);
appointmentsContainer.setScrollableY(true);
appointmentsContainer.refreshTheme();
// getContentPane().
content.revalidate();
content.add(BorderLayout.CENTER, appointmentsContainer);
if (folder.equals(Server.AppointmentFolders.APPOINTMENTS)) {
Button startActivityAppt = new Button("Start");
FontImage.setMaterialIcon(startActivityAppt, FontImage.MATERIAL_ASSIGNMENT, hText);
SITUtil.makeBorderRound(startActivityAppt);
content.add(BorderLayout.SOUTH, startActivityAppt);
startActivityAppt.addActionListener(e -> {
new ActivityForm(null).show();
});
}
// content.repaint();
}
答案 0 :(得分:0)
调用refresh()
将清除容器的内容,然后再次调用fetchComponents()
。
因为您的代码还具有状态,所以您可能还需要这样做:
counterDate = currentDate;