lundi 30 août 2021

How to access and change Spinners and Checkboxes in a ListView in Android Studio

I am creating a smart house and in the edit page I need to preload the spinner and checkboxes with the values that the user inputed before. I cant seem to access them. they are in a listview with an array adapter. Is there a different way to access them?

the code where i am trying to access the spinner:

 ArrayAdapter arScenarioOn = new ArrayAdapter(this, R.layout.layout_dropdown_add,ComboPage.options.toArray());
    
        programAdapter = new ComboAddAdapter(this, Items.area,Items.progImag, isChecked,arScenarioOn);
        applianceListview.setAdapter(programAdapter);
    
    
        groupNameTil.getEditText().setText(name);
    
    
       for (int i = 0; i < programAdapter.getCount(); i++) {
            Spinner d = programAdapter.getView(i,null,applianceListview).findViewById(R.id.spinner_scenario);
            TextView dview = programAdapter.getView(i,null,applianceListview).findViewById(R.id.textView_title_group);
            dview.setText("I win");
           //applianceListview.getChildAt(i).findViewById(R.id.spinner_scenario);
           d.setSelection(2);
        }

Code for the single item in list view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="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:orientation="horizontal"
    android:visibility="visible"
    android:descendantFocusability="blocksDescendants"
    tools:visibility="visible"
    >

    <ImageView
        android:id="@+id/imageView_group"
        android:layout_width="68dp"
        android:layout_height="64dp"
        android:layout_margin="10dp"
        android:src="@drawable/picture_lightbuldyellow" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="74dp"
        android:orientation="horizontal">


        <TextView
            android:id="@+id/textView_title_group"
            android:layout_width="77dp"
            android:layout_height="48dp"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:paddingTop="20dp"
            android:text="@string/title"
            android:textSize="20sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Spinner
            android:id="@+id/spinner_scenario"
            android:layout_width="117dp"
            android:layout_height="match_parent"
            android:layout_marginTop="22dp"
            android:layout_marginEnd="15dp"

            android:layout_marginRight="15dp"
            android:textSize="8sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/checkBox"
            app:layout_constraintTop_toTopOf="parent" />

        <CheckBox
            android:id="@+id/checkBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_weight="2"
            android:outlineAmbientShadowColor="@color/green"
            android:outlineSpotShadowColor="@color/green"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


    </androidx.constraintlayout.widget.ConstraintLayout>


</LinearLayout>



Aucun commentaire:

Enregistrer un commentaire