Android Open Source - HealthInput Next Activity

From Project

Back to project page HealthInput.


The source code is released under:

GNU General Public License

If you think the Android project HealthInput listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.patient;
//from w  w  w  .ja va  2  s .c o m
import java.util.Calendar;
import java.util.StringTokenizer;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class NextActivity extends Activity {
  EditText dFirstName;
  EditText dMiddleName;
  EditText dLastName;
  RadioButton dGenderFem;
  RadioButton dGenderMale;
  RadioButton dMarried;
  RadioButton dSingle;
  EditText dSocialSec;
  EditText dAddress;
  EditText dAddress2;
  EditText dCity;
  Spinner dState;
  EditText dZipCode;
  EditText dEmail;
  EditText dPhone;

  private String initialDate;
  private String initialMonth;
  private String initialYear;
  DatePickerDialog datePicking2 = null;
  private EditText date; 
  private String title; 
  Context context;
  int fromReview;

  protected void onCreate(Bundle savedInstanceState) {
    date = (EditText) findViewById(;
    context = getApplicationContext();
    title = "Choose your date of birth";
    //next page button
    Button b = (Button) findViewById(;
    //gets the value 1 if this activity was started by the review page
    //otherwise the value is 0
    fromReview = getIntent().getIntExtra("review", 0);
    dFirstName = (EditText) findViewById(;
    dMiddleName = (EditText) findViewById(;
    dLastName = (EditText) findViewById(;
    dGenderFem = (RadioButton) findViewById(;
    dGenderMale = (RadioButton) findViewById(;
    dMarried = (RadioButton) findViewById(;
    dSingle = (RadioButton) findViewById(;
    dSocialSec = (EditText) findViewById(;
    dAddress = (EditText) findViewById(;
    dAddress2 = (EditText) findViewById(;
    dCity = (EditText) findViewById(;
    dState = (Spinner) findViewById(; 
    dZipCode = (EditText) findViewById(;
    dEmail = (EditText) findViewById(;
    dPhone = (EditText) findViewById(;
    //tasks the activity performs when it is started by the review page
    if (fromReview == 1){
      //sets the next button to finish button 
      //gets the respective data through the review page in an array 
      String[] patientDetails = getIntent().getStringArrayExtra("details");
      //assigns the data to specific variables
      final String iFirstName = patientDetails[0];
      final String iMiddleName = patientDetails[1];
      final String iLastName = patientDetails[2];    
      final String iGender = patientDetails[3];
      final String iDOB = patientDetails[4];
      final String iStatus = patientDetails[5];
      final String iSSN = patientDetails[6];
      final String iAddress = patientDetails[7];
      final String iCity = patientDetails[8];
      final String iState = patientDetails[9];
      final String iZip = patientDetails[10];
      final String iEmail = patientDetails[11];
      final String iPhone = patientDetails[12];
      final String iAddress2 = patientDetails[13];
      //fill out the page with the retrieved data through the review page
      if (iGender == "Gender: Female"){
      else {
      if (iStatus == "Marital Status: Married"){
      else {
      dState.setSelection(getIntent().getIntExtra("selected_state", -1));
    //button to pop up the datepicker 
        ImageButton dateButton = (ImageButton) findViewById(;
        dateButton.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
            Calendar  dtTxt = null;
            String preExistingDate = (String) date.getText().toString();
            if (preExistingDate != null && !preExistingDate.equals("")) {
              StringTokenizer st = new StringTokenizer(preExistingDate,"/");
              initialMonth = st.nextToken();
              initialDate = st.nextToken();
              initialYear = st.nextToken();
              if (datePicking2 == null) {
                datePicking2 = new DatePickerDialog(v.getContext(), new PickDate(), Integer.parseInt(initialYear), 
                    Integer.parseInt(initialMonth) - 1, Integer.parseInt(initialDate));                
              datePicking2.updateDate(Integer.parseInt(initialYear), Integer.parseInt(initialMonth) - 1, 
            else {
              dtTxt = Calendar.getInstance(); 
              if (datePicking2 == null) {
                datePicking2 = new DatePickerDialog(v.getContext(), new PickDate(), dtTxt.getTime().getYear(),dtTxt.getTime().getMonth(), 
              datePicking2.updateDate(dtTxt.getTime().getYear(), dtTxt.getTime().getMonth(), dtTxt.getTime().getDay());
                DatePicker dateCeption = datePicking2.getDatePicker();
        // when the next page button is clicked
        b.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
            Intent i;
            if (fromReview == 1) {
              //if this activity is started by the review page 
              //the intent is assigned with a value that starts the review page
              i = new Intent(NextActivity.this, ReviewActivity.class);
              //Data of the employment history section from the review page
              final String[] employmentHist = getIntent().getStringArrayExtra("employment_history");

              //Data of the emergency contact section from the review page
              final String[] emergencyContact = getIntent().getStringArrayExtra("emergency_contact");

              //Data of the insurance section from the review page
              final String[] insurance = getIntent().getStringArrayExtra("insurance_Data");

              //Data of the medical history section from the review page
              final String[] medHistory = getIntent().getStringArrayExtra("medical_History_Data");
              //Data of the allergy section from the review page
              final String[] allergies = getIntent().getStringArrayExtra("allergies");
              //put the data from the other activities for the review page
              i.putExtra("employment_history", employmentHist);

                i.putExtra("emergency_contact", emergencyContact);

                i.putExtra("insurance_Data", insurance);
                i.putExtra("medical_History_Data", medHistory);
                i.putExtra("allergies", allergies);
            else {
              //the intent is assigned with a value that start the next activity
              i = new Intent(NextActivity.this, NextActivity2.class);
            //gets the data entered by the user
            String firstName = dFirstName.getText().toString();
            String middleName = dMiddleName.getText().toString();
            String lastName = dLastName.getText().toString();
            String genderSelected = "Gender: not selected";
        if (dGenderFem.isChecked()) {
          genderSelected = "Gender: Female";      
        if (dGenderMale.isChecked()) {
              genderSelected = "Gender: Male";
            String birthDate = date.getText().toString();
            String status = "Marital Status: not selected";
            if (dMarried.isChecked()) {
              status = "Marital Status: Married";
            if (dSingle.isChecked()) {
              status = "Marital Status: Single";
            String ssn = dSocialSec.getText().toString();
            String address1 = dAddress.getText().toString();

            String address2 = dAddress2.getText().toString();

            String city = dCity.getText().toString();
            String state = dState.getItemAtPosition(dState.getSelectedItemPosition()).toString();
            int statePos = dState.getSelectedItemPosition();
            i.putExtra("selected_state", statePos);
            String zip = dZipCode.getText().toString();
            String email = dEmail.getText().toString();
            String phone = dPhone.getText().toString(); 
            //puts the data in an array 
            String[] patientDetails = { firstName, middleName, lastName, genderSelected, birthDate, status, ssn, address1, city, state, zip,
                          email, phone,  address2 };
            //puts the array in an intent to be sent to the next activity 
            i.putExtra("details", patientDetails);
        //clear button 
    Button clearButton = (Button) findViewById(;
    clearButton.setOnClickListener (new View.OnClickListener()
      public void onClick(View w)
        clearAll((ViewGroup) findViewById(;

  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;
  private class PickDate implements DatePickerDialog.OnDateSetListener {

      public void onDateSet(DatePicker view, int year, int monthOfYear,
              int dayOfMonth) {
          view.updateDate(year, monthOfYear + 1, dayOfMonth);

//clear button for edittexts and radiogroups
  public void clearAll(ViewGroup root) 
      for (int i = 0, j = root.getChildCount(); i < j; i++) 
          View view = root.getChildAt(i);
          if (view instanceof ViewGroup) 
              clearAll((ViewGroup) view);
          if (view instanceof EditText) 
              ((EditText) view).setText("");
          ViewGroup parent = (ViewGroup) findViewById(;
          for (int k = 0; k < parent.getChildCount(); k++) 
              View currentView = parent.getChildAt(k);
              if (currentView instanceof RadioGroup) 
                  ((RadioGroup) currentView).clearCheck();

Java Source Code List