Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:44:25+00:00 2026-06-18T06:44:25+00:00

My Update method in DataBaseHandler Class public void updateProject(Project project){ SQLiteDatabase db = this.getWritableDatabase();

  • 0

My Update method in DataBaseHandler Class

    public void updateProject(Project project){
         SQLiteDatabase db = this.getWritableDatabase();
         ContentValues values = new ContentValues();
         values.put(PROJECT_NAME, project.getName()); // Contact Name
         values.put(PROJECT_DESCRIPTION, project.getDescription()); // Contact Phone
         values.put(CLIENT_NAME, project.getClient_name());
         values.put(LOCATION, project.getLocation());
         String where = PROJECT_ID + " = ? ";       
         String [] value = { String.valueOf(project.getProject_id()) };
         try{
             int count = db.update(TABLE_PROJECT, values, where , value);
             Log.d(LOG_TAG, "Updated rows -> " + count);
         }catch (Exception e) {
            e.printStackTrace();
        }
        db.close();
    }
}

The java bean class

public class Project implements Serializable{

    private static final long serialVersionUID = 1L;
    private int project_id;
    private String name;
    private String description;
    private String client_name;
    private String location;

    public Project(){

    }

    public Project(int project_id, String name, String client_name,String description, String location){
        this.project_id = project_id;
        this.name = name;
        this.description = description;
        this.client_name = client_name;
        this.location = location;
    }

    public int getProject_id() {
        return project_id;
    }

    public void setProject_id(int project_id) {
        this.project_id = project_id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getClient_name() {
        return client_name;
    }

    public void setClient_name(String client_name) {
        this.client_name = client_name;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

}

The activity which adds and updates the project item from list view

public class AddProjectActivity extends Activity implements Serializable{

    private static final long serialVersionUID = 1L;
    private MenuItem saveItem;
    private DatabaseHandler dbHelper;
    private static final String TITLE = "Add Project";
    public boolean isEdit = false;
    private static final String LOG_TAG = "debugger";
    private Project editedProject;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_project);
        setTitle(TITLE);
        dbHelper = DatabaseHandler.getInstance(this);           

        //get intent from Project Fragment when project is edited
        Intent intent = getIntent();
        if(intent.hasExtra(IntentConstants.PROJECT_ITEM)){
            Project project = (Project) intent.getSerializableExtra(IntentConstants.PROJECT_ITEM);
            if(project != null){
                this.isEdit = true;
                setEditedProject(project);
                setProjectData(project);
            }
        }
    }          



    private void setProjectData(Project project){
        EditText projectName = (EditText) findViewById(R.id.editTextProjectName);
        projectName.setText(project.getName());
        EditText clientName = (EditText) findViewById(R.id.editTextProjectClient);
        clientName.setText(project.getClient_name());
        EditText projectDesc = (EditText) findViewById(R.id.editTextProjectDesc);
        projectDesc.setText(project.getDescription());
        EditText projectLocation = (EditText) findViewById(R.id.editTextProjectLocation);
        projectLocation.setText(project.getLocation());
    }



@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.saveButton:
           if(isEdit == true){
              updateProject();
           }else{
              saveProject();
           }
           finish();
        break;
     case R.id.cancelButton:
        finish();
        break;
     default:
        break;
    }
 return true;
}

    private void updateProject(){
      dbHelper.updateProject(getProjectData(getEditedProject()));
    }

    public boolean isEdit() {
        return isEdit;
    }

    public void setEdit(boolean isEdit) {
        this.isEdit = isEdit;
    }

    private Project getProjectData(Project newProject){
        EditText projectName = (EditText) findViewById(R.id.editTextProjectName);
        String project = projectName.getText().toString();
        EditText clientName = (EditText) findViewById(R.id.editTextProjectClient);
        String client = clientName.getText().toString();
        EditText projectDesc = (EditText) findViewById(R.id.editTextProjectDesc);
        String description = projectDesc.getText().toString();
        EditText projectLocation = (EditText) findViewById(R.id.editTextProjectLocation);
        String location = projectLocation.getText().toString();

        newProject.setName(project);
        newProject.setClient_name(client);
        newProject.setDescription(description);
        newProject.setLocation(location);
        return newProject;
    }

    public Project getEditedProject() {
        return editedProject;
    }

    public void setEditedProject(Project editedProject) {
        this.editedProject = editedProject;
    }

}

My ListFragment method that handles the click of listview item. It passes the data to AddProjectActivity using Intent

@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        if(dbHelper != null){
            Project project = (Project) this.getListAdapter().getItem(position);
            Intent intent = new Intent(getActivity(), AddProjectActivity.class);
            intent.putExtra(IntentConstants.PROJECT_ITEM, project);
            startActivity(intent);
            this.isEdit = true;
        }
    }

The problem I have is when listview item is edited and updated by user it never gets updated in database. The rowcount returned by update method is always zero.

I am not able to fix this issue.

Can someone help please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:44:26+00:00Added an answer on June 18, 2026 at 6:44 am

    I found the issue. I wasn’t setting the id of Project object in ListView. So the id was never matched and nothing was updated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Update method like this: public void Update(MyClass item, System.Linq.Expressions.Expression<Func<MyClass, bool>> exp)
I have created this Update method public void Update(Person updated) { var oldProperties =
I'v created a Contentprovide and implements it's update() method like this: @Override public int
I have the following update method in my generic Repository public class Repository<T> :
I've some probleme with merge. My update method works in this way: void update(Parent
I have the following code class sample { public void update(List l) { l
I have a simple update method in my manager class and I need to
I am attempting to add an update method to the Symbol class. class SymbolUpdate(s:
I'm new to Esper and I was wondering if the update method of an
I have a problem with the logic of this code, XNA's Update Method is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.