Hello,
I've been stuck on a little bug trying to implement a custom listview in Java for an Android application.
I'm trying to list a bunch words (typically, 100 < n < 500) and highlight a subset of those rows by changing the text color. The both sets of words (global and subset) are listed in a collection (currently an ArrayList)
The problem is that some words are missing. It seems random. I think it might be more likely that the words intended for 'highlighting' are missing. (I.e. I've tried a couple different variations of code, but here is what I've currently got:
public class ResultsAdapter<T> extends ArrayAdapter<String> {
private ArrayList<String> mHighlightSet;
private ArrayList<String> mGlobalSet;
private Context mContext;
public ResultsAdapter(
Context context,
int textViewResourceId,
ArrayList<String> globalSet,
ArrayList<String> highlightSet) {
super(context, textViewResourceId, globalSet);
mContext = context;
mGlobalSet = globalSet;
mHighlightSet = highlightSet;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// return super.getView(position, convertView, parent);
final String text = mGlobalSet.get(position);
TextView view = new TextView(mContext);
view.setText(text);
if(mHighlightSet.contains(text))
view.setTextColor(Color.RED);
else
view.setTextColor(Color.WHITE);
return view;
}
This custom adapter gets instantiated and assigned by the following code:
if (mSummaryList != null & mAllWords != null & foundWords != null) {
ArrayList<String> globalSet = new ArrayList<String>(mAllWords.keySet()); // mAllWords is a TreeMap
ArrayList<String> subset = hud.getFoundWords();
mResultsAdapter = new ResultsAdapter<String>(this, R.layout.simplerow, globalSet, subset);
mSummaryList.setAdapter(mResultsAdapter);
mSummaryList.setOnItemClickListener(onWordListItemClickListener);
}
It appears that there's some disconnect between the data variables, and what shows up on the screen. I'm lost, please help.
Thanks in advance!