Example #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
      LayoutInflater vi =
          (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      v = vi.inflate(R.layout.track_list, null);
    }
    Room room = items.get(position);
    if (room != null) {
      TextView text1 = (TextView) v.findViewById(R.id.text1);
      TextView textSmall = (TextView) v.findViewById(R.id.text_small);

      if (text1 != null && textSmall != null) {
        text1.setText(room.getName());
        textSmall.setText("Room");
      }
    }
    return v;
  }
  public Schedule parse() throws ParserException {
    try {
      List<Day> days = new ArrayList<Day>();
      Event event = null;
      List<Event> events = null;
      List<Room> rooms = null;
      Conference conference = null;

      Day day = null;
      Room room = null;

      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();

      xpp.setInput(stream, "UTF-8");

      @SuppressWarnings("unused")
      String content = null;

      int eventType = xpp.getEventType();
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
          launchEvent(xpp.getName(), ParserEventListener.TAG_OPEN);
          if (xpp.getName().equals(CONFERENCE)) {
            xpp.next();
            conference = parseConference(xpp);
          } else if (xpp.getName().equals(DAY)) {
            Date date = null;
            int idx = 0;
            for (int i = 0; i < xpp.getAttributeCount(); i++) {
              if (xpp.getAttributeName(i).equals(DATE)) {
                date = DateUtil.getDate(xpp.getAttributeValue(i));
              } else if (xpp.getAttributeName(i).equals(INDEX)) {
                idx = Integer.parseInt(xpp.getAttributeValue(i));
              }
            }
            day = new Day(date, idx);
            rooms = new ArrayList<Room>();

          } else if (xpp.getName().equals(ROOM)) {
            String name = null;
            for (int i = 0; i < xpp.getAttributeCount(); i++) {
              if (xpp.getAttributeName(i).equals(NAME)) {
                name = xpp.getAttributeValue(i);
              }
            }
            room = new Room(name);
            events = new ArrayList<Event>();
          } else if (xpp.getName().equals(EVENT)) {
            int id = -1;
            for (int i = 0; i < xpp.getAttributeCount(); i++) {
              if (xpp.getAttributeName(i).equals(ID)) {
                id = Integer.parseInt(xpp.getAttributeValue(i));
              }
            }
            xpp.next();
            Event e = parseEvent(xpp, day);
            e.setId(id);
            room.addEvent(e);
          }
          content = null;
        } else if (eventType == XmlPullParser.END_TAG) {
          launchEvent(xpp.getName(), ParserEventListener.TAG_CLOSED);
          if (xpp.getName().equals(DAY)) {
            day.addRooms(rooms);
            days.add(day);
            rooms = null;
          } else if (xpp.getName().equals(ROOM)) {
            room.addEvents(events);
            rooms.add(room);
            events = null;
          } else if (xpp.getName().equals(EVENT)) {
            events.add(event);
            event = null;
          }
        } else if (eventType == XmlPullParser.TEXT) {
          content = xpp.getText();
        }
        eventType = xpp.next();
      }
      return new Schedule(conference, days);
    } catch (Exception e) {
      throw new ParserException(e);
    }
  }