Note that there are some explanatory texts on larger screens.

plurals
  1. POLicense problem using sectioned ListView with J. Sharkey's SeparatedListAdapter
    text
    copied!<p>big explanation (better safe...), question in bold if you don't want to read it all. Thanks a lot for your help!</p> <p>I have an app with a <code>ListView</code>, and two custom XMLs. One is a single TextView, for the headers. The other has 3 TextViews and 3 ImageViews that represent the data.</p> <p>As most of you know, <a href="http://jsharkey.org/" rel="nofollow noreferrer">Jeff Sharkey</a> already has a <a href="http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/" rel="nofollow noreferrer">very clever (imho) solution</a> (<code>SeparatedListAdapter</code>), which allows the class to work, without modifications, with ImageViews. Although it accepts <code>String</code>s, I can provide the <code>valueOf</code> of the drawable int resources, and it will figure it out. Great, see code and screen at end (his class not here for simplicity).</p> <p>The problem is that, <strong>for my project, I've been given a stack of in-house, proprietary code to work with. And Sharkey's code is GPLv3, which rules out the possibility of me using his code. So maybe you could know a solution that would allow me to link to that code without my other code being "attracted" to the force of the GPL</strong>. I'm not discussing the politics of it, so I appreciate if you don't. Besides, I'm not circumventing, I'm avoiding it legally.</p> <p>Right now, I've been able to find <a href="https://github.com/commonsguy/cwac-merge" rel="nofollow noreferrer">cwac-merge</a>, which is ASL 2. But so far I couldn't "map" the strings and drawables to custom TextViews and ImageViews in a custom XML layout. Also, the example app uses a completely different approach to what I think I remotely need.</p> <p>In case you care to see what I'm up to, see <code>SeparatedListAdapter</code> and my class below. For cwac-merge, it force closes no matter what, so I won't bother posting.</p> <pre><code>package com.uitests; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import android.app.ListActivity; import android.os.Bundle; import android.widget.SimpleAdapter; public class TestActivity extends ListActivity { public final static String ITEM_TITLE = "title"; public final static String ITEM_STATE = "state"; public final static String ITEM_TEMPERATURE = "temperature"; public final static String ITEM_UP = "up"; public final static String ITEM_DOWN = "down"; public final static String ITEM_LEVEL = "level"; public Map&lt;String,?&gt; createItem( String title, String state, String temperature, String upImage, String downImage, String levelImage) { Map&lt;String,String&gt; item = new HashMap&lt;String,String&gt;(); item.put(ITEM_TITLE, title); item.put(ITEM_STATE, state); item.put(ITEM_TEMPERATURE, temperature); item.put(ITEM_UP, upImage); item.put(ITEM_DOWN, downImage); item.put(ITEM_LEVEL, levelImage); return item; } @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // THIS IS JUST AN EXAMPLE TO POPULATE THE LIST FOR STACKOVERFLOW! List&lt;Map&lt;String,?&gt;&gt; controlA = new LinkedList&lt;Map&lt;String,?&gt;&gt;(); controlA.add(createItem( "Monitor 001AK", "Functional", "27", String.valueOf(R.drawable.ic_up), String.valueOf(R.drawable.ic_down_off), String.valueOf(R.drawable.ic_level07))); // MORE .adds HERE List&lt;Map&lt;String,?&gt;&gt; controlB = new LinkedList&lt;Map&lt;String,?&gt;&gt;(); controlB.add(createItem( "Monitor 003CK", "Functional", "29", String.valueOf(R.drawable.ic_up), String.valueOf(R.drawable.ic_down_off), String.valueOf(R.drawable.ic_level07))); // MORE .adds HERE SeparatedListAdapter adapter = new SeparatedListAdapter(this); adapter.addSection( "Control 1", new SimpleAdapter( this, controlA, R.layout.equip_row, new String[] { ITEM_TITLE, ITEM_STATE, ITEM_TEMPERATURE, ITEM_UP, ITEM_DOWN, ITEM_LEVEL }, new int[] { R.id.tide_row_title, // TextView R.id.tide_row_state, // TextView R.id.tide_row_temperature, // TextView R.id.tide_row_img_up, // ImageView R.id.tide_row_img_down, // ImageView R.id.tide_row_img_level } // ImageView ) ); adapter.addSection( "Control 2", new SimpleAdapter( this, controlB, R.layout.equip_row, new String[] { ITEM_TITLE, ITEM_STATE, ITEM_TEMPERATURE, ITEM_UP, ITEM_DOWN, ITEM_LEVEL }, new int[] { R.id.tide_row_title, R.id.tide_row_state, R.id.tide_row_temperature, R.id.tide_row_img_up, R.id.tide_row_img_down, R.id.tide_row_img_level } ) ); this.getListView().setAdapter(adapter); } } </code></pre> <p>all that simplicity results in this great screen:</p> <p><img src="https://i.stack.imgur.com/SneQT.png" alt="Jeff Sharkey&#39;s implementation of Sectioned ListViews"></p>
 

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