package com.example.componentsproject;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

    String[] predmeti = {"PIA", "KDP", "VD", "PKI", "ORT"};

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

        CheckBox cb = findViewById(R.id.checkbox);
        cb.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if(isChecked) Toast.makeText(getApplicationContext(), "yes", Toast.LENGTH_SHORT).show();
            else Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_SHORT).show();
        });

        Spinner sp = findViewById(R.id.dropdown);
        sp.setOnItemSelectedListener(this);

        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item , predmeti);
        sp.setAdapter(adapter);

    }

    public void onRadioButtonClicked(View view){
        boolean checked = ((RadioButton)view).isChecked();

        if(checked){
            switch(view.getId()){
                case R.id.radioM:
                    Toast.makeText(getApplicationContext(), "musko", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.radioZ:
                    Toast.makeText(getApplicationContext(), "zensko", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(getApplicationContext(), predmeti[position], Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
}