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 String
s, 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:
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.