Newer
Older
CosmosClient / app / src / main / java / com / example / cosmosclient / views / AddRequestActivity.java
package com.example.cosmosclient.views;

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.EditText;
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.ArrayList;


public class AddRequestActivity extends AppCompatActivity {
    private Request requestList;

    private EditText editTextProduct;

    private Button addButon;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_request);

         editTextProduct = findViewById(R.id.editTextProduct);

         Spinner category = findViewById(R.id.spinnerLocationCategory);

         addButon = findViewById(R.id.buttonAdd);

         addButon.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 // エディットテキストのテキストを取得
                 String inputProduct = editTextProduct.getText().toString();
                 // 取得したテキストを TextView に張り付ける
                 Request requestlist = (new Request(inputProduct, new Date(2019, 6, 7), "スーパー", "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);
    }


}