3

big explanation (better safe...), question in bold if you don't want to read it all. Thanks a lot for your help!

I have an app with a ListView, and two custom XMLs. One is a single TextView, for the headers. The other has 3 TextViews and 3 ImageViews that represent the data.

As most of you know, Jeff Sharkey already has a very clever (imho) solution (SeparatedListAdapter), which allows the class to work, without modifications, with ImageViews. Although it accepts Strings, I can provide the valueOf of the drawable int resources, and it will figure it out. Great, see code and screen at end (his class not here for simplicity).

The problem is that, 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. 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.

Right now, I've been able to find cwac-merge, 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.

In case you care to see what I'm up to, see SeparatedListAdapter and my class below. For cwac-merge, it force closes no matter what, so I won't bother posting.

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<String,?> createItem(
        String title, String state, String temperature, 
        String upImage, String downImage, String levelImage) {  

    Map<String,String> item = new HashMap<String,String>();  
    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<Map<String,?>> controlA = new LinkedList<Map<String,?>>();  
    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<Map<String,?>> controlB = new LinkedList<Map<String,?>>();  
    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);  

}  

}

all that simplicity results in this great screen:

Jeff Sharkey's implementation of Sectioned ListViews

davidcesarino
  • 16,160
  • 16
  • 68
  • 109
  • 5
    I'm voting to close this question as off-topic because **it is about licensing or legal issues**, not programming or software development. [See here](http://meta.stackoverflow.com/a/274964/1402846) for details, and the [help/on-topic] for more. – Kevin Brown-Silva Jun 12 '15 at 23:51
  • @KevinBrown I agree. I was a novice back then and didn't fully understand the on-topic limitations of Stack Overflow. – davidcesarino Jun 14 '15 at 00:08

2 Answers2

1

I believe one of the main goals of GPLv3 was to prevent people exploiting loopholes they'd found in earlier versions, so I don't think this will be a possibility.

If this is a show-stopper for you, it might be worth contacting Jeff to see if you can license code on different terms - Applying GPL to code doesn't stop it being made available by the author/copyright hold under a different license.

That said, doesn't ExpandableListAdapter and ExpandableListView do almost the same job, if you override the expand/collapse behaviour?

Hope this helps,

Phil Lello

Phil Lello
  • 8,377
  • 2
  • 25
  • 34
  • I even contacted him, but anyway... now that I've looked at everything a bit more, it's clear that his intention was really to make it available under the GPL... understandable. Truth is, I'm not that familiar with Adapters, so maybe I need to learn a bit more before asking. I'm looking into ExpandableListAdapter, but my problem is exactly the "stitching" part. But thanks for the tip. – davidcesarino Apr 16 '11 at 21:01
  • Something similar is on my 'to do' list, if I implement it over the next few days, I'll post it here. – Phil Lello Apr 16 '11 at 21:27
  • Wow, thanks. Meanwhile, I'm also looking into cwac-merge google group, since SeparatedListAdapter is indeed ruled out. If I manage to find a way to make it work, I'll post it here :-). I'm by no means an Android expert (or Java expert), so let's see. – davidcesarino Apr 16 '11 at 23:21
  • Sheesh, it just force closes. Anyway... I'd guess that by now Android would provide a reusable, "no frills" code for creating headers in listviews. I'm thinking about hacking everything together in one XML and just setting "visibility.gone" on the header TextView when it's not a header, and vice-versa. Sure... I'd provide fake Strings to "flag" that, but at least it would... appear. Sorry for the rant, btw. – davidcesarino Apr 17 '11 at 00:02
0

OK, I managed to make it work using cwac-merge. I got help from people here.

I won't reinvent the wheel, so you can all read the information there (including the code used). I can clarify if needed. Just ask and I'll help.

davidcesarino
  • 16,160
  • 16
  • 68
  • 109