• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to create date picker and store the result in Date variable

fizznicus

Lurker
Hello everybody, I recently started learning Android development. I would really appreciate if someone can help me with a problem I'm having. With minimum API 21, how to create a Date picker for user to select a date, then store the value into a Date variable, and then convert into a String. I'm writing my code in Java and I'm using Android Studio 3.0. I have a tried a few Youtube tutorials, but the biggest problem is that my minimum API is set to 21, while tutorials only show for API 24+. Please, if someone can help me, I would be really grateful.
 
MainActivity.java

Code:
package com.example.fizznicus.bicikla05;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;

public class MainActivity extends AppCompatActivity {

    private static Button login;
    private static Button register;

    [USER=1021285]@override[/USER]
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        onClickButtonListener();
    }

    public void onClickButtonListener(){
        login = (Button)findViewById(R.id.main_login);
        register =(Button)findViewById(R.id.main_register);


        login.setOnClickListener(new View.OnClickListener() {
            [USER=1021285]@override[/USER]
            public void onClick(View v) {
                Intent intent = new Intent (MainActivity.this, LoginActivity.class);
                startActivity(intent);
            }
        });

        register.setOnClickListener(new View.OnClickListener() {
            [USER=1021285]@override[/USER]
            public void onClick(View v) {
                Intent intent = new Intent (MainActivity.this, RegisterActivity.class);
                startActivity(intent);
            }
        });


    }


}



activity_main.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="102dp"
        android:layout_height="49dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        app:layout_constraintVertical_bias="0.098" />
</android.support.constraint.ConstraintLayout>

basically, I only started making the simple app, but I am already stuck. API is 21, which is giving me the most headache so far
 
Last edited by a moderator:
Back
Top Bottom