コード例 #1
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //noinspection ConstantConditions
    TextView pesel = (TextView) getView().findViewById(R.id.pesel);
    TextView name = (TextView) getView().findViewById(R.id.name);
    TextView numberOfExams = (TextView) getView().findViewById(R.id.number_of_exams);
    TextView passedExams = (TextView) getView().findViewById(R.id.passed_exams);
    TextView averageResult = (TextView) getView().findViewById(R.id.average_result);

    try {
      final StudentSummary studentSummary =
          dataSource.getStudentSummary(UserActivity.getCurrentPesel());

      /* App is in only one language so let's do a bad thing and leave hardcoded
       * strings. Normally strings should be got from resources and formatted.
       */
      String peselLine = "PESEL: " + studentSummary.getPesel();
      String nameLine = studentSummary.getFirstName() + " " + studentSummary.getSurname();
      String examsNoLine = "Liczba egzaminów: " + studentSummary.getNumberOfExams();
      String passedExamsLine = "Zdane egzaminy: " + studentSummary.getPassedExams();
      String averageLine = "Średni rezultat: " + studentSummary.getAverageResult() + "%";

      pesel.setText(peselLine);
      name.setText(nameLine);
      numberOfExams.setText(examsNoLine);
      passedExams.setText(passedExamsLine);
      averageResult.setText(averageLine);

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  /**
   * Every list view item is processed here to make it look just like I want to.
   *
   * @param position position
   * @param convertView convertView
   * @param parent parent
   * @return a converted view
   */
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    StudentSummary item = getItem(position);

    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null)
      convertView =
          LayoutInflater.from(getContext())
              .inflate(R.layout.list_item_teacher_student, parent, false);

    TextView info = (TextView) convertView.findViewById(R.id.info);
    TextView exams = (TextView) convertView.findViewById(R.id.exams);
    TextView average = (TextView) convertView.findViewById(R.id.average);

    /* App is in only one language so let's do a bad thing and leave hardcoded
     * strings. Normally strings should be got from resources and formatted.
     */
    String infoLine =
        item.getFirstName() + " " + item.getSurname() + " (PESEL: " + item.getPesel() + ")";
    String examsLine =
        "Zdawał: " + item.getNumberOfExams() + "   zaliczył: " + item.getPassedExams();
    String averageLine = "Średnia: " + item.getAverageResult() + "%";

    info.setText(infoLine);
    exams.setText(examsLine);
    average.setText(averageLine);

    return convertView;
  }