Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting checkbox status inside a view
    primarykey
    data
    text
    <p>I have a layout which is being used as a template for a view. This view is being spawned multiple times and I want to access the values of some checkboxes which are part of the view.</p> <p>This is my xml template:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/motor_block" android:layout_width="wrap_content" android:layout_height="30dp" android:orientation="horizontal" android:background="@drawable/motor_shape"&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|left" android:layout_margin="5dp" android:text="Motor" /&gt; &lt;CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:tag="A" android:text="A" /&gt; &lt;CheckBox android:id="@+id/checkBox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:tag="B" android:text="B" /&gt; &lt;CheckBox android:id="@+id/checkBox3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:tag="C" android:text="C" /&gt; &lt;EditText android:id="@+id/editText1" android:layout_width="40dp" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="number" android:maxLength="2" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; </code></pre> <p></p> <p>I cant get the status doing</p> <pre><code> CheckBox A = (CheckBox)findViewById(R.id.checkBox1); </code></pre> <p>because it will get the status of the checkbox of the first view that was spawned.</p> <p>Any ideas of how to get the status?</p> <p><strong>EDIT</strong></p> <p>I defined it:</p> <pre><code> HashMap boxes = new HashMap(); </code></pre> <p>Then I added the CheckBox with the view as a key:</p> <pre><code> boxes.put(iv,(CheckBox)findViewById(R.id.checkBox1)); </code></pre> <p>But when I do this:</p> <pre><code> CheckBox A = boxes.get(v); </code></pre> <p>I get this: <em>Type mismatch: cannot convert from Object to CheckBox</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload