Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom ListView Adapter [Android]
    text
    copied!<p>I've been stuck on a little bug trying to implement a custom listview in Java for an Android application.</p> <p>I'm trying to list a bunch words (typically, 100 &lt; n &lt; 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)</p> <p>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:</p> <pre><code> public class ResultsAdapter&lt;T&gt; extends ArrayAdapter&lt;String&gt; { private ArrayList&lt;String&gt; mHighlightSet; private ArrayList&lt;String&gt; mGlobalSet; private Context mContext; public ResultsAdapter( Context context, int textViewResourceId, ArrayList&lt;String&gt; globalSet, ArrayList&lt;String&gt; 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; } </code></pre> <p>This custom adapter gets instantiated and assigned by the following code:</p> <pre><code> if (mSummaryList != null &amp; mAllWords != null &amp; foundWords != null) { ArrayList&lt;String&gt; globalSet = new ArrayList&lt;String&gt;(mAllWords.keySet()); // mAllWords is a TreeMap ArrayList&lt;String&gt; subset = hud.getFoundWords(); mResultsAdapter = new ResultsAdapter&lt;String&gt;(this, R.layout.simplerow, globalSet, subset); mSummaryList.setAdapter(mResultsAdapter); mSummaryList.setOnItemClickListener(onWordListItemClickListener); } </code></pre> <p>It appears that there's some disconnect between the data variables, and what shows up on the screen. I'm lost, please help.</p> <p>Thanks in advance!</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