Почему не выбирается элемент в Spinner?

В spinner подгружаю значения из БД, но при клике по одному из элементов он не выбирается. Цвет шрифта и бэкграунда проверял, через логи тоже пытался посмотреть срабатывает ли выбор элемента. Несколько дней гуглил, но так и не нашел ответа. Подскажите, пожалуйста, в чем ошибка.

activity_add.xml:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="32dp">

    <TextView
        android:id="@+id/tvAdd"
        style="@style/PageTitle"
        android:layout_width="0dp"
        android:layout_marginLeft="@dimen/fab_margin"
        android:text="@string/add_domain"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tiDomain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/fab_margin"
        android:layout_marginTop="@dimen/fab_margin"
        android:layout_marginRight="@dimen/fab_margin"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvAdd">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/domainName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/text_name"
            android:inputType="textPersonName"
            android:text=""
            android:theme="@style/EditTextTheme" />
    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tiDate"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/fab_margin"
        app:layout_constraintEnd_toEndOf="@+id/tiDomain"
        app:layout_constraintStart_toStartOf="@+id/tiDomain"
        app:layout_constraintTop_toBottomOf="@+id/tiDomain">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/domainDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/edit_text_date"
            android:inputType="date"
            android:text=""
            android:theme="@style/EditTextTheme" />
    </com.google.android.material.textfield.TextInputLayout>


    <Spinner
        android:id="@+id/spinner"
        style="@style/SpinnerMy"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/fab_margin"
        android:descendantFocusability="blocksDescendants"
        android:spinnerMode="dropdown"
        app:layout_constraintEnd_toEndOf="@+id/tiDomain"
        app:layout_constraintStart_toStartOf="@+id/tiDomain"
        app:layout_constraintTop_toBottomOf="@+id/tiDate" />

    <Button
        android:id="@+id/add"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/action_save"
        style="@style/BtnGreenStyle"
        app:layout_constraintEnd_toEndOf="@+id/tiDomain"
        app:layout_constraintStart_toStartOf="@+id/tiDomain"
        app:layout_constraintTop_toBottomOf="@+id/spinner" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        app:layout_constraintBottom_toBottomOf="parent"></com.google.android.gms.ads.AdView>



</androidx.constraintlayout.widget.ConstraintLayout>

AddActivity

public class AddActivity extends AppCompatActivity {

    private AppDataBase myDb;
    private EditText addName, addDate;
    private TextView addTitle;
    private String nameVal, dateVal, projectVal;
    private Spinner spinner;
    private Button add;
    private boolean isEdit = false;
    private boolean newRecord = false;
    private int id;
    private List<ProjectName> projects;
    private List<Project> projectUnit;
    private List<ProjectName> projectListArray;
    private Calendar calendar = Calendar.getInstance();
    private List<String> spinnerArray = new ArrayList<>();
    private AdView mAdView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        init();
        getMyIntent();
        addDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDateDialog();
            }
        });
        addDate.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    showDateDialog();
                }
            }
        });
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                save(v);
            }
        });
    }

    @Override
    public void onPause() {
        if (mAdView != null) {
            mAdView.pause();
        }
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mAdView != null) {
            mAdView.resume();
        }
    }

    @Override
    public void onDestroy() {
        if (mAdView != null) {
            mAdView.destroy();
        }
        super.onDestroy();
    }

    private void showDateDialog() {
        DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                calendar.set(Calendar.YEAR, year);
                calendar.set(Calendar.MONTH, month);
                calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                setDate();
            }
        };
        DatePickerDialog datePickerDialog = new DatePickerDialog(AddActivity.this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, dateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        datePickerDialog.show();
    }

    private void init() {
        myDb = AppDataBase.getInstance(this);
        addName = findViewById(R.id.domainName);
        addDate = findViewById(R.id.domainDate);
        addTitle = findViewById(R.id.tvAdd);
        add = findViewById(R.id.add);
        spinner = findViewById(R.id.spinner);
        projectListArray = new ArrayList<>();
        AppExecuter.getInstance().getDiscIO().execute(new Runnable() {
            @Override
            public void run() {
                projects = myDb.projectDAO().getNameProjectList();
                AppExecuter.getInstance().getMainIO().execute(new Runnable() {
                    @Override
                    public void run() {
                        projectListArray.clear();
                        projectListArray.addAll(projects);
                        if(projects != null && projects.size() > 0) {
                            int i = 0;
                            for (ProjectName project : projects) {
                                spinnerArray.add(project.getName());
                            }
                        } else {
                            spinnerArray.add(getString(R.string.spinner_error));
                        }
                    }
                });
            }
        });
        ArrayAdapter<String> ad = new ArrayAdapter(this, R.layout.spinner_item, spinnerArray);
        ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(ad);
        spinner.setSelection(0);
        Log.d("DOMAIN", "Spinner Item selected is: " + spinner.getSelectedItem());
        ad.notifyDataSetChanged();
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String item = projectListArray.get(position).getName();
                Log.d("DOMAIN", "Spinner Item selected is: " + item);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                Log.d("DOMAIN", "Spinner Item not selected! ");
            }
        });
        setDate();
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
        mAdView.loadAd(adRequest);
    }

    private void setDate(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date d = new Date(calendar.getTimeInMillis());
        addDate.setText(sdf.format(d));
    }

    private void setIsEdit(boolean isEdit){
        this.isEdit = isEdit;
    }

    private void getMyIntent(){
        Intent intent = getIntent();
        if(intent != null) {
            if(intent.getStringExtra(Constants.TYPE) != null) {
                setIsEdit(false);
                addTitle.setText("Add " + intent.getStringExtra(Constants.TYPE));
                id = intent.getIntExtra(Constants.ID_KEY, 0);
                newRecord = false;
            } else {
                newRecord = true;
            }
        }
    }

    private void save(View view) {
        Intent intent = getIntent();
        nameVal = addName.getText().toString();
        dateVal = addDate.getText().toString();
        projectVal = spinner.getSelectedItem().toString();
        Log.d("DOMAIN", "domain: " + nameVal + "; date: " + dateVal + "; project: " + projectVal);
    }

    private void saveIs(String type, String name, String date, int projectId) {
        switch (type) {
            case "domain":
                Domain domain = new Domain(name, date, projectId);
                myDb.domainDAO().insertDomain(domain);
                finish();
                break;

            case "host":
                Host host = new Host(name, date, projectId);
                myDb.hostDAO().insertHost(host);
                finish();
                break;

            case "ssl":
                Ssl ssl = new Ssl(name, date, projectId);
                myDb.sslDAO().insertSsl(ssl);
                finish();
                break;
        }
    }

}

До открытия списка: До открытия списка

Выбираю: Выбираю

Высота спиннера визуально увеличивается, но поле пустое: Высота спиннера визуально увеличивается, но поле пустое

Логи: 2020-12-17 15:23:49.029 9583-9583/ru.bampro.webhostingcalendar D/DOMAIN: Spinner Item selected is: null


Ответы (0 шт):