package com.example.cosmosclient.views; import android.app.DatePickerDialog; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; import android.widget.ImageButton; import android.widget.Spinner; import android.widget.TextView; import com.example.cosmosclient.R; import com.example.cosmosclient.entities.Request; import java.sql.Date; import java.util.Calendar; public class AddRequestActivity extends AppCompatActivity { private Request requestList; private ImageButton calenderButton; private EditText editTextProduct; private int curYear; private int curMonth; private int curDayOfMonth; private EditText editTextDeadline; private Button addButon; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_request); calenderButton = findViewById(R.id.calenderButton); editTextProduct = findViewById(R.id.editTextProduct); editTextDeadline = findViewById(R.id.editTextDeadline); Spinner category = findViewById(R.id.spinnerLocationCategory); addButon = findViewById(R.id.buttonAdd); calenderButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Calendarインスタンスを取得 final Calendar calender = Calendar.getInstance(); //DatePickerDialogインスタンスを取得 DatePickerDialog datePickerDialog = new DatePickerDialog(AddRequestActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { curYear = year; curMonth = month; curDayOfMonth = dayOfMonth; //setした日付を取得して表示 editTextDeadline.setText(String.format("%d / %02d / %02d", year, month+1, dayOfMonth)); } }, calender.get(Calendar.YEAR), calender.get(Calendar.MONTH), calender.get(Calendar.DATE) ); //dialogを表示 datePickerDialog.show(); } }); addButon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // エディットテキストのテキストを取得 String inputProduct = editTextProduct.getText().toString(); // 取得したテキストを TextView に張り付ける RequestListActivity.requestlist.add((new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), "スーパー", "a-hongo"))); startActivity(new Intent(AddRequestActivity.this, RequestListActivity.class)); } }); // リスナーを登録 category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { // アイテムが選択された時 @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Spinner spinner = (Spinner)parent; String selectedCategory = (String)spinner.getSelectedItem(); SearchSubCategory(selectedCategory); } // アイテムが選択されなかった public void onNothingSelected(AdapterView<?> parent) { } }); } private void SearchSubCategory(String selectedCategory) { } private void setSpinner(Spinner spinner, String[] arr){ ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arr); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); } }