Hallo,
ich habe folgenden Code:
Code
public void addAllEvents(Calendar c1_init_previous2, Calendar c2_init_next) {
Events events = new Events(this.c);
ArrayList<ReadEvent> alldatesmonthly_init_previous = events.getAllEventsByMonth(c1_init_previous2, c2_init_next);
Calendar calen = Calendar.getInstance();
TimeZone tz = calen.getTimeZone();
long calendar_millis = c1_init_previous2.getTimeInMillis();
calendar_millis = ((calendar_millis + tz.getOffset(calendar_millis)) / 1000) * 1000;
for(int i = 0; i < alldatesmonthly_init_previous.size(); i++) {
String eventname = alldatesmonthly_init_previous.get(i).getEventname();
long dtstart = alldatesmonthly_init_previous.get(i).getDtstart();
long difference = (dtstart - calendar_millis) / 1000 / 24 / 60 /60;
if(difference >= 0 && difference < 42) {
long dtend = alldatesmonthly_init_previous.get(i).getDtend();
long calendarid = alldatesmonthly_init_previous.get(i).getCalendarid();
/*if(readevent.getDtstart() < calendar_millis && readevent.getDtend() > calendar_millis) {
readevent.setDtstart(calendar_millis);
}
if((readevent.getDtstart() >= calendar_millis && readevent.getDtstart() < calendar_millis + 86400000) || (readevent.getDtstart() <= calendar_millis && readevent.getDtend() >= calendar_millis + 86400000)) {
*/
this.addDate((int)difference, dtstart, dtend, eventname, events.getCalendarColor(calendarid));
}
}
}
private void addDate(int numoflinearlayout, long from, long to, String title, String color) {
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
TimeZone tz = c1.getTimeZone();
TimeZone tz2 = c2.getTimeZone();
from = ((from - tz.getOffset(from)) / 1000) * 1000;
to = ((to - tz2.getOffset(to)) / 1000) * 1000;
c1.setTimeInMillis(from);
c2.setTimeInMillis(to);
showPopup(numoflinearlayout, title, color);
}
private void showPopup(int numoflinearlayout, String title, String color) {
final LinearLayout linearlayout = new LinearLayout(this.c);
final LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.setMargins(0, 1, 0, 0);
linearlayout.setLayoutParams(layout);
int color_parsed;
try {
color_parsed = Color.parseColor(color);
} catch(Exception e) {
color_parsed = (0xff000000 + Integer.parseInt(color));
}
//Color.parseColor(color)
linearlayout.setBackgroundColor(color_parsed);
linearlayout.setOrientation(LinearLayout.HORIZONTAL);
final TextView txtview2 = new TextView(this.c);
txtview2.setText(title);
txtview2.setTextSize(11);
txtview2.setSingleLine(false);
final LinearLayout linearlayout3 = new LinearLayout(this.c);
final LinearLayout.LayoutParams layout3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
linearlayout3.setLayoutParams(layout3);
linearlayout3.setOrientation(LinearLayout.HORIZONTAL);
linearlayout3.addView(txtview2);
linearlayout.addView(linearlayout3);
linearlayouts.get(numoflinearlayout).addView(linearlayout);
}
Alles anzeigen
Ich habe das Problem, dass in der for-Schleife bei ungefähr 200 Datensätzen die App für 3-4 Sekunden hängt.
Gibt es eine Möglichkeit, diese Datensätze erst dann hinzuzufügen, wenn das GUI geladen ist?
Oder habt ihr noch andere Ideen, um die for-Schleife schneller zu machen.
Das Problem macht folgende Zeile NICHT:
Code
ArrayList<ReadEvent> alldatesmonthly_init_previous = events.getAllEventsByMonth(c1_init_previous2, c2_init_next);
Sondern: Es ist die for-Schleife. Keine Ahnung, wie ich sie beschleunigen kann.
Am besten wäre es, wenn die Methode addAllEvents() im Hintergrund laufen würde. Wie kann ich das anstellen?