Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have to expand only 2 views, then perhaps you can use a simple trick to achieve this without <code>ExpandableListView</code>. Just define the layout of every category and subcategory in a <code>LinearLayout</code> oriented <code>vertically</code>, with the the visibility of subcategories by default to be <code>gone</code>. </p> <pre><code>&lt;LinearLayout android:id="@+id/category1" //....&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/subcategory1" android:visibility="gone" //....&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/category2" //....&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/subcategory2" android:visibility="gone" //....&gt; &lt;/LinearLayout&gt; </code></pre> <p>Set a click listener for each category, and when a category is clicked change its visibility: to <code>visible</code> if it's <code>gone</code>, and to <code>gone</code> if it's <code>visible</code>.</p> <p>A pseudo cod will look like this:</p> <pre><code>ViewGroup category1 = findViewById(category1); ViewGroup subcategory1 = findViewById(subcategory1); category1.setOnClickListener(new OnClickListener(){ public void onClick(){ toogle(); } }); //...... void toogle(){ if(subcategory1 is visible){ subcategory1.visibility = "gone" }else{ subcategory1.visibility = "visible" } } </code></pre> <p>In case in the future the requirements will change and you'll have to add more categories, then perhaps the <code>ExpandableListView</code> would make more sense, but for now you can achieve the desired effect with this simple trick.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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