Main3Activity.java 2.33 KB
package com.example.ksi.refrigerator;

import android.app.DatePickerDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Calendar;
import java.util.Date;

public class Main3Activity extends AppCompatActivity {

    Intent intent;
    Item item;

    TextView name;
    TextView date;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        name = findViewById(R.id.name);
        date = findViewById(R.id.datepick);

        intent = getIntent();

        item = (Item) intent.getSerializableExtra("item");

        name.setText(item.name);

        item.image = "https://us.123rf.com/450wm/utima/utima1512/utima151200012/50417381-%EC%8B%A0%EC%84%A0%ED%95%9C-%EB%B9%A8%EA%B0%84-%EC%82%AC%EA%B3%BC-%ED%99%94%EC%9D%B4%ED%8A%B8%EC%97%90-%EA%B2%A9%EB%A6%AC%EC%9E%85%EB%8B%88%EB%8B%A4-%ED%81%B4%EB%A6%AC%ED%95%91-%ED%8C%A8%EC%8A%A4%EC%99%80-%ED%95%A8%EA%BB%98.jpg?ver=6";
    }

    public void addItem(View view){
        Intent mainIntent = new Intent();
        mainIntent.putExtra("item2",item);
        setResult(RESULT_OK,mainIntent);
        finish();
    }
    public void datePick(View view) {
        Calendar pickedDate = Calendar.getInstance();
        Calendar minDate = Calendar.getInstance();

        DatePickerDialog datePickerDialog = new DatePickerDialog(
                Main3Activity.this,
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int year, int month, int dayofMonth) {
                        Toast.makeText(getApplicationContext(), "select date : " + year + "-" + (month + 1) + "-" + dayofMonth, Toast.LENGTH_LONG).show();
                        date.setText(year + "-" + (month + 1) + "-" + dayofMonth);
                        item.date = new Date(year,month,dayofMonth);
                    }
                },
                pickedDate.get(Calendar.YEAR),
                pickedDate.get(Calendar.MONTH),
                pickedDate.get(Calendar.DATE)
        );

        datePickerDialog.show();
    }
}