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 8688739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:27:07+00:00 2026-06-12T23:27:07+00:00

In my app I have 2 buttons which opens a Time Dialog/Date Dialog and

  • 0

In my app I have 2 buttons which opens a Time Dialog/Date Dialog and then I select the date and time and then press OK. Thefore the value gets shown in a TextView (for each one), so I need to get the VALUE from the TextViews and save it in the database.

database row = date

Code for Time shown in TextView:

tvHora = (TextView) findViewById(R.id.tvHora);

    final Calendar d = Calendar.getInstance();
    hour = d.get(Calendar.HOUR_OF_DAY);
    minute = d.get(Calendar.MINUTE);

    //set current time into textview
    tvHora.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));

Code for Date shown in TextView:

tvData = (TextView) findViewById(R.id.tvData);

    final Calendar c = Calendar.getInstance();
    year = c.get(Calendar.YEAR);
    month = c.get(Calendar.MONTH);
    day = c.get(Calendar.DAY_OF_MONTH);

    //SET CURRENT DATE INTO TEXTVIEW

    tvData.setText(new StringBuilder().append(year).append("-").append(month + 1).append("-").append(day).append("-"));

Code when I click the SAVE button:

                        ContentValues valor = new ContentValues();
                        valor.put("mensagenssalvas", resultado);
                        db.insert("mensagens", null, valor);

So how do I get the values from the textviews to save in the database?

EDIT
TimePicker Dialog:

private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {

        public void onTimeSet(TimePicker view, int selectedHour, int selectedMinute) {
            // TODO Auto-generated method stub

            hour = selectedHour;
            minute = selectedMinute;

            //set current time into textview
            tvHora.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));

        }
    };

DatePicker Dialog:

 private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {

        public void onDateSet(DatePicker view, int Year, int monthOfYear,
                int dayOfMonth) {
            // TODO Auto-generated method stub

            year = Year;
            month = monthOfYear;
            day = dayOfMonth;

            // set selected date into textview
            tvData.setText(new StringBuilder().append(month + 1)
                .append("-").append(day).append("-").append(year)
                .append(" "));
        }

    }; 
  • 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-12T23:27:10+00:00Added an answer on June 12, 2026 at 11:27 pm

    I would store the value as an number in SQLite to make it compatible since SQLite doesn’t have built in date/time data types.

    You will want to save the value in the DatePicke’s OnDateSetListener.

    To give you an example on how to do this is exactly depends largely on how you create the date pickers. Assuming the values are set you can use the code below. Note that it assumes tvData and tvHora are in class properties (global variables to the class), this way you can reuse them once you set them (which should be done in onCreate)
    Perhaps something like this would work:

    private final SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    //keep your current code for the date/time pickers..
    
    public void saveData(View button) {
        String dateStr = tvData.getText().toString();
        String timeStr = tvHora.getText().toString();
    
        //only save if both fields are non empty 
        if (!TextUtils.isEmpty(dateStr) && !TextUtils.isEmpty(timeStr)) {
           try {
             Date d = parser.parse(dateStr + " " + timeStr);
             ContentValues valor = new ContentValues();
             valor.put("mensagenssalvas", d.getTime());
             db.insert("mensagens", null, valor);
           } catch(ParseException ex) {
              Log.e("YOURTAG", "Error parsing date", ex);
           }
        } else {
          Log.d("YOURTAG", "Both fields not present, can't save");
        }
    
    }
    

    In your xml layout for the file make a save button like this:

    <Button  android:id="@+id/Save"
                android:onClick="saveData"
                android:text="Save" />
    

    Or if you don’t want to put the onClick in xml, you can do the same thing in code like this:

    Button saveButton = findViewById(R.id.save);
    saveButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View button) {
            saveData(button);
          }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have a few buttons in my iPhone app (which may be
I have an view in my App which has a number of buttons based
I have made an iPhone App which has a loginwithFacebook button , the login
I have a small data collection app which has a single button to start
I have a page X in my grails app which has a button to
my app have action bar on top of windows. Where are some buttons. Buttons
I have two buttons in my flex app next to each other, ButtonA and
I have several buttons on my app that are being created dynamically. They are
So I have these buttons in my app that I want to open .PDF
In my app there is requirement that..I have 6 buttons in a nib, when

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.