Esempio n. 1
0
 @Override
 public void onClick(View v) {
   String content =
       "课程名:"
           + course.getCourseName()
           + "\n"
           + "上课时间:"
           + course.getDetail()
           + "\n"
           + "授课教师:"
           + course.getTeacher()
           + "\n"
           + "地点:"
           + course.getRoom();
   DialogUtil.showMsg(getActivity(), content);
 }
Esempio n. 2
0
  public int processJson(String json) {
    courseContainer.removeAllViews();
    int len = 0;
    try {
      L.d("解析所有课程", json);
      JSONArray jsonArray;
      jsonArray = new JSONArray(json);
      len = jsonArray.length();

      for (int i = 0; i < len; i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        Course course = new Course(jsonObject);

        // 将dp转换成px,因为设置RelativeLayout.LayoutParams 的margin只能传入px
        int _60dp = dpToPx(getActivity(), 60);
        int marginDp = dpToPx(getActivity(), 1.5f);

        int colWidth = courseContainer.getWidth() / 7;
        int xStartOffset = (Integer.valueOf(course.getLessonsBegin()) - 1) * (_60dp + marginDp);
        int xEndOffset = (Integer.valueOf(course.getLessonsEnd()) - 1) * (_60dp + marginDp);
        int yStartOffset = (Integer.valueOf(course.getDayOfWeek()) - 1) * colWidth;

        LinearLayout ll =
            (LinearLayout)
                LayoutInflater.from(getActivity()).inflate(R.layout.layout_onecourse, null);

        TextView courseName = (TextView) ll.findViewById(R.id.courseName);
        //				TextView detail = (TextView) ll.findViewById(R.id.detail);
        //				TextView teacher = (TextView) ll.findViewById(R.id.teacher);
        TextView room = (TextView) ll.findViewById(R.id.room);

        courseName.setText(course.getCourseName());
        // detail.setText(course.getDetail());
        // teacher.setText(course.getTeacher());
        room.setText(course.getRoom());

        RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(colWidth, xEndOffset - xStartOffset + _60dp);
        params.leftMargin = yStartOffset;
        params.topMargin = xStartOffset;

        courseContainer.addView(ll, params);

        ll.setOnClickListener(new CourseOnClickListener(course));
      }

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return len;
  }