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

  • SEARCH
  • Home
  • 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 9119801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:28:55+00:00 2026-06-17T05:28:55+00:00

I am having an issue where the item is getting inserted to my db

  • 0

I am having an issue where the item is getting inserted to my db twice. I dont have 2 insert statements.

I am trying to check if an array’s element is empty.

Here are snippets of my code

In my main activity

private String[] dateTimeDispStr= new String[2];

in onCreate:

dateTimeDispStr[0]=null;
dateTimeDispStr[1]=null;

Other parts of same activity:

//-------------------------------------------update time----------------------------------------//    
public void updatetime()
{
    dateTimeDispStr[0]=new StringBuilder()
    .append(pad(mhour)).append(":")
    .append(pad(mminute)).toString();

    tdv.editRow(this, dateTimeDispStr);
    if(dateTimeDispStr[1]!=null){
        update();
    }

}

//-------------------------------------------update date----------------------------------------//    
private void updateDate() {
    dateTimeDispStr[1]=new StringBuilder()
    // Month is 0 based so add 1
    .append(mMonth + 1).append("/")
    .append(mDay).append("/")
    .append(mYear).append(" ").toString();

    tdv.editRow(this, dateTimeDispStr);
    if(dateTimeDispStr[0]!=null){
        update();
    }

}


SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:MM");

public void update(){
    Calendar cal = Calendar.getInstance();
    cal.set(mYear, mMonth + 1, mDay, mhour, mminute, 0);
    String date = formatter.format(cal.getTime());

    tdi.setDate(date.split(" ")); // split makes an array of ["date", "time"]
    db.addItem(tdi);
    Log.d("Item set in the db", "The item: " + date);
}

Here is my database handler

// Adding new ToDoItem
public void addItem(ToDoItem item) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_TASK, item.getTDItem()); // item task
        values.put(KEY_DATE, item.getDate()); // item date
        values.put(KEY_PRIORITY, item.getPriority()); // item priority

        // Inserting Row
        db.insert(TABLE_TDL, null, values);
        db.close(); // Closing database connection
    }

tdv.editRow edits the row on my UI that is extending a table layout. I will add the functionality for checking for null in a sec. It essentially appends the row that already had the task of the todo item, but with date and time I would like to add them to that row

I understand that I call update in both methods, but that is because if the user clicks either button first.

  • 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-17T05:28:56+00:00Added an answer on June 17, 2026 at 5:28 am

    Instead of all that I would simply fetch a Calendar instance, populate it with your date / time variables, and use a DateFormat to build a localized String.

    Try this update() by itself:

    // Create a field variable
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm"); // HH for 24hr
    
    public void update(){
        Calendar cal = Calendar.getInstance();
        cal.set(mYear, mMonth + 1, mDay, mhour, mminute, 0);
        String date = formatter.format(cal.getTime());
    
        tdi.setDate(date.split(" ")); // split makes an array of ["date", "time"]
        db.addItem(tdi);
        Log.d("Item set in the db", "The item: " + date);
    }
    

    (I don’t have a working compiler at the moment so forgive any minor flaws…)
    Read about customizing the SimpleDateFormat string here.

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

Sidebar

Related Questions

I am having issues getting my remove element function working. I have this function:
I am having an issue that I have spend way too much time trying
I am having an issue trying to get an array out of JS using
Hi guys I am having issue I have this query: SELECT * FROM useraccount
Just started mongo and started having issue with querying already. i have a collection
Having an issue with random individuals trying to access an intranet site with a
Having an issue here that I have tried everything I can think of but
I'm having an issue trying to get an accurate running total for my calculations.
I'm having an issue with an event handler in SharePoint. I have a list
I am having an issue where the item in the dropdown list is not

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.