0

I currently have three buttons, one is for Update, which allows the title to be updated. Delete, which allows the database entry to be deleted. These currently work fine.

I have added a third button called Complete (completeBtn). When the user presses the Complete button i would like the EditText (titleText) to be changed to "Marked Complete" and the title entry to be changed in the database. I think i am pretty close, but not sure what the problem is.

There is currently no error being show, but when i press the Complete button it does not change the EditText for titleText to "Marked Complete" or change the value for title stored in the database to "Marked Complete"

Any help would be appreciated. :)

ModifyDeadlines.java

package com.example.pc.achieve;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ModifyDeadline extends Activity implements OnClickListener {

private EditText titleText;
private Button updateBtn, completeBtn, deleteBtn;
private EditText descText;

private long _id;

private DBManager dbManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle("Modify Record");

    setContentView(R.layout.activity_modify_record);

    dbManager = new DBManager(this);
    dbManager.open();

    titleText = (EditText) findViewById(R.id.subject_edittext);
    descText = (EditText) findViewById(R.id.description_edittext);

    updateBtn = (Button) findViewById(R.id.btn_update);
    deleteBtn = (Button) findViewById(R.id.btn_delete);

    completeBtn = (Button) findViewById(R.id.btn_complete);
    titleText.setText( "Marked Complete" + completeBtn.getText() );

    Intent intent = getIntent();
    String id = intent.getStringExtra("id");
    String name = intent.getStringExtra("title");
    String desc = intent.getStringExtra("desc");

    _id = Long.parseLong(id);

    titleText.setText(name);
    descText.setText(desc);

    updateBtn.setOnClickListener(this);
    deleteBtn.setOnClickListener(this);
    completeBtn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_update:
        case R.id.btn_complete:
            String title = titleText.getText().toString();
            String desc = descText.getText().toString();

            dbManager.update(_id, title, desc);
            this.returnHome();
            break;

        case R.id.btn_delete:
            dbManager.delete(_id);
            this.returnHome();
            break;
    }
}

public void returnHome() {
    Intent home_intent = new Intent(getApplicationContext(), ViewDeadlines.class)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(home_intent);
}
}
4
  • What is the issue? Commented Mar 17, 2017 at 17:40
  • you need to tell us where is the error!! Commented Mar 17, 2017 at 17:40
  • There is currently no error being show, but when i press the Complete button it does not change the EditText to "Marked Complete" or change the value for title stored in the database to "Marked Complete". Commented Mar 17, 2017 at 17:41
  • 1
    The value of TextView can be updated via settext method. But on your button click, you do not call this method to update the value. Commented Mar 17, 2017 at 17:44

1 Answer 1

1

I think you are miss matching your button click implementation

try this;

 @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_update:

                String title = titleText.getText().toString();
                String desc = descText.getText().toString();

                dbManager.update(_id, title, desc);
                this.returnHome();
                break;   //missing break statement

            case R.id.btn_complete:
                titleText.setText( "Marked Complete" + completeBtn.getText());
                complete();
                break;

            case R.id.btn_delete:
                dbManager.delete(_id);
                this.returnHome();
                break;
        }
    }

    public void complete(){
        String title = titleText.getText().toString();
        String desc = descText.getText().toString();

        dbManager.update(_id, title, desc);
    }
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks that does now update the EditText, but the database title is not being updated. When i try to add dbManager.update(_id, title, desc); underneath the code you have provided i get an error that it's already been defined in the scope?
String title = titleText.getText().toString(); String desc = descText.getText().toString();
you can use different variable name like: String title1 = titleText.getText().toString(); String desc1 = descText.getText().toString();
I have tried doing that, but it causes an error for the variable not being initialised for dbManager.update(_id, title, desc); As these are the names which are used in the database.
That has worked! Thank you very to the members who have helped. I can see you moved it to a new complete method and it has helped my understanding too. I appreciate your time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.