Question

Create an app that has two DatePicker components. The user should select his or her birthdate...

Create an app that has two DatePicker components. The user should select his or her birthdate with the first DatePicker and some date in the future with the second DatePicker. The app should display how old the user will be on the second date.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Enter your date of birth:"
            android:textSize="20sp"/>

        <DatePicker
            android:id="@+id/PickDateOfBirth"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#4BE226"
            android:datePickerMode="spinner"
            android:layout_marginTop="15dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Enter today's date:"
            android:textSize="20sp"
            android:layout_marginTop="15dp"/>

        <DatePicker
            android:id="@+id/PickTodaysDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#E9AC2F"
            android:datePickerMode="spinner"
            android:layout_marginTop="15dp"/>

        <Button
            android:id="@+id/Findage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Find my age"
            android:textAllCaps="false"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"/>

        <TextView
            android:id="@+id/age"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15sp"/>


    </LinearLayout>


</RelativeLayout>

MainActivity.java

package com.example.datepicker;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView age = (TextView)findViewById(R.id.age);
        Button findage = (Button)findViewById(R.id.Findage);
        final DatePicker dateOfBirth = (DatePicker)findViewById(R.id.PickDateOfBirth);
        final DatePicker TodaysDate = (DatePicker)findViewById(R.id.PickTodaysDate);

        findage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int years = TodaysDate.getYear() - dateOfBirth.getYear();
                age.setText("Your age is: "+years);
            }
        });

    }
}
Add a comment
Know the answer?
Add Answer to:
Create an app that has two DatePicker components. The user should select his or her birthdate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi, I am trying to create a simple android app using spinners. It need not be...

    Hi, I am trying to create a simple android app using spinners. It need not be very complex. The app should allow the user to use a simple spinner to select a team from the following list of teams (Kansas City Chiefs, New England Patriots, New Orleans Saints, and the Los Angeles Rams), once the user selects the team they wish to view, the app should display a small paragraph of information (hardcoded) To the screen for the user to...

  • Write an Android App that calculates the days remaining from the current date until the user...

    Write an Android App that calculates the days remaining from the current date until the user selected date. Display a fragment which has a single button labeled “Select Date”.   When that button is pushed a Dialog should be displayed with a DatePicker widget inside. After the user selects the date, calculate the difference in days and display it back on the original fragment.

  • This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display...

    This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display a weather forecast for the user’s current location Create the app titled Weather Forecaster The first screen will have a textbox for the user to enter a zip code and a button to submit When the user enters the zip code and clicks the button, the app will navigate to the weather forecast screen. The weather forecast screen will show the current weather for...

  • Lab: User login system (python) Create a user login system. Your code should do the following:...

    Lab: User login system (python) Create a user login system. Your code should do the following: 1.Load your user database from “UD.txt” (USE THE EXACT FILE NAME, file is given in the folder) 2.Display “Login or create a new user? Select L to login, select C to create new user.” 3. If wrong selection is entered, take the user back to step 2. 4. If the user entered “L”, display “Please enter your user name and hit enter” 5. Check...

  • Create a Student Planner app that will allow students to keep track of homework due dates...

    Create a Student Planner app that will allow students to keep track of homework due dates for the classes they are currently taking. The first app activity (screen) will display the list of classes the student has entered. There should also be a way for students to add, edit, and remove classes from the list. When students select a class they should be taken to a second activity (screen) which will display the assignment name and due date (at minimum,...

  • Using AndroidStudio Create a mobile app UI that has the following labels and textboxes. Customer Name...

    Using AndroidStudio Create a mobile app UI that has the following labels and textboxes. Customer Name Customer ID Customer Address The mobile app UI should also contain a Submit button. The following validation should be executed as soon as user clicks the Submit button. Customer ID should be between 0-1000. If user enters any value above 1000, then you need to display an error message. Customer Name should not contain any numeric characters. If user enters customer name with numbers,...

  • Tip Calculator App For this project, you will create a tip calculator Android app. The user...

    Tip Calculator App For this project, you will create a tip calculator Android app. The user should enter their bill amount into an EditText and then select the desired tip percentage using a SeekBar. When the user moves the SeekBar’s dial, the tip amount and total amount are displayed in separate TextViews below. Your Tip Calculator App should very closely resemble the one shown here: Widgets • At the top of the app, include a TextView that contains your name...

  • PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for...

    PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for the user's most challenging course at Wilmington University. The second prompt should ask for the user's second most challenging course. The red boxes indicate the input from the user. Your program should respond with two copies of an enthusiastic comment about both courses. Be sure to include the input provided by the user to display the message. There are many ways to display a...

  • Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows...

    Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows users to register and login into the system. The focus of this project is for you to create an app with several activities and has data validation. You should have for your app: A welcome screen (splash screen) with your app name and a picture. You should then move to a screen that asks the user for either to log in or to register....

  • Your app is computing and displaying tax for the user, in the format “Hello John Doe,...

    Your app is computing and displaying tax for the user, in the format “Hello John Doe, Your Tax is: ......” , where John Doe is the name entered, and .... indicates the tax amount as a dollar figure. Your form has two textboxes, where the user will enter his/her name, and income, and click a Submit button. Your app will store the name entered by the user into a variable of type String, and store the income into a variable...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT