Exemple #1
0
  public void save() {
    //
    //        Intent intent=getIntent();
    //        profileId=intent.getIntExtra("profile_id",0);

    // icareDS=new ProfileDataSource(getApplicationContext());

    //        HashMap<String, String> map = new HashMap<String, String>();
    //        map= icareDS.getAboutOneProfile(profileId);
    //        Log.v("map value", map.toString());

    mName = etName.getText().toString();
    mAge = etAge.getText().toString();
    mBloodGroup = String.valueOf(etBloodGroup.getSelectedItem());
    mWeight = etWeight.getText().toString();
    mHeight = etHeight.getText().toString();
    mDateOfBirth = etDateOfBirth.getText().toString();
    mSpecialNotes = etSpecialNotes.getText().toString();

    // Assign values in the ICareProfile
    Profile profileDataInsert =
        new Profile(mName, mAge, mBloodGroup, mWeight, mHeight, mDateOfBirth, mSpecialNotes, image);
    profileDataInsert.setName(mName);
    profileDataInsert.setAge(mAge);
    profileDataInsert.setBloodGroup(mBloodGroup);
    profileDataInsert.setWeight(mWeight);
    profileDataInsert.setHeight(mHeight);
    profileDataInsert.setDateOfBirth(mDateOfBirth);
    profileDataInsert.setSpecialNotes(mSpecialNotes);
    profileDataInsert.setImage(image);

    /*
     * if update is needed then update otherwise submit
     */
    icareDS = new ProfileDataSource(getBaseContext());
    if (icareDS.insert(profileDataInsert)) {
      toast = Toast.makeText(this, getString(R.string.successfullySaved), Toast.LENGTH_LONG);
      toast.show();
      startActivity(new Intent(ProfileCreate.this, MainActivity.class));
    } else {
      toast = Toast.makeText(this, getString(R.string.notSaved), Toast.LENGTH_LONG);
      toast.show();
    }
  }
  private void init() {

    // set the textfield id to the variable.
    et_name = (EditText) findViewById(R.id.viewName);
    et_age = (EditText) findViewById(R.id.viewAge);
    etBloodGroup = (EditText) findViewById(R.id.viewBloodGroup);
    et_weight = (EditText) findViewById(R.id.viewWeight);
    et_height = (EditText) findViewById(R.id.viewHeight);
    et_dateOfBirth = (EditText) findViewById(R.id.viewDOB);
    et_specialNotes = (EditText) findViewById(R.id.viewSpComment);
    btnImage = (ImageView) findViewById(R.id.imageViewCreate);
    updateProfile = (Button) findViewById(R.id.updateProfile);
    updateProfile.setOnClickListener(mCorkyListener);
    // home_btn = (Button) view.findViewById(R.id.buttonHome);

    //
    //		 * get the profile which include all data from database according
    //		 * profileId of the clicked item.

    mDataSource = new ProfileDataSource(this);
    mUpdateProfile = mDataSource.singleProfileData();

    if (mUpdateProfile != null) {
      mName = mUpdateProfile.getName();
      // mAge = mUpdateProfile.getAge();
      mBloodGroup = mUpdateProfile.getBloodGroup();
      mWeight = mUpdateProfile.getWeight();
      mHeight = mUpdateProfile.getHeight();
      mDateOfBirth = mUpdateProfile.getDateOfBirth();
      mSpecialNotes = mUpdateProfile.getSpecialNotes();
      image = mUpdateProfile.getImage();
    }

    // Add the line
    mAge = ageCal2.calAge(mDateOfBirth);

    // set the value of database to the text field.
    et_name.setText(mName);
    et_age.setText(mAge);
    etBloodGroup.setText(mBloodGroup);
    et_weight.setText(mWeight);
    et_height.setText(mHeight);
    et_dateOfBirth.setText(mDateOfBirth);
    et_specialNotes.setText(mSpecialNotes);
    et_dateOfBirth.setOnClickListener(this);
  }
        public void onClick(View v) {
          mName = et_name.getText().toString();
          mAge = et_age.getText().toString();
          mBloodGroup = etBloodGroup.getText().toString();
          mWeight = et_weight.getText().toString();
          mHeight = et_height.getText().toString();
          mDateOfBirth = et_dateOfBirth.getText().toString();
          mSpecialNotes = et_specialNotes.getText().toString();

          // Assign values in the ICareProfile
          Profile profileDataInsert = new Profile();
          profileDataInsert.setName(mName);
          profileDataInsert.setAge(mAge);
          profileDataInsert.setBloodGroup(mBloodGroup);
          profileDataInsert.setWeight(mWeight);
          profileDataInsert.setHeight(mHeight);
          profileDataInsert.setDateOfBirth(mDateOfBirth);
          profileDataInsert.setSpecialNotes(mSpecialNotes);

          mDataSource = new ProfileDataSource(getBaseContext());

          if (mDataSource.updateData(1, profileDataInsert) == true) {
            Intent intent = new Intent(ProfilePreviewUpdate.this, MainActivity.class);
            startActivity(intent);
            toast =
                Toast.makeText(
                    ProfilePreviewUpdate.this,
                    getString(R.string.successfullyUpdated),
                    Toast.LENGTH_LONG);
            toast.show();
            // displayView();

          } else {
            toast =
                Toast.makeText(
                    ProfilePreviewUpdate.this, getString(R.string.notUpdated), Toast.LENGTH_LONG);
            toast.show();
          }
        }