Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3235390
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:30:04+00:00 2026-05-17T17:30:04+00:00

I’ve been stuck on a little bug trying to implement a custom listview in

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:30:04+00:00Added an answer on May 17, 2026 at 5:30 pm

    It might help if you test it out with a small number of words, so you can better see if you actually have a problem. I’m assuming that mAllWords is some sort of map. By doing mAllWords.keySet() you are getting the words in a random order. This probably makes it hard to tell if a word is actually there or not. You should try sorting the words there, or using some known ordered set so you can better tell whats going on.

    Also, in getView you do not want to be creating a TextView. This is really inefficient. Instead, you should get a view from the already inflated layout and update the styling. I.e, something like:

    public View getView(int position, View convertView, ViewGroup parent) {
      View view = super.getView(position, convertView, parent);
    
      TextView textView = view.findById(R.id.text);  // id of the text view in R.layout.simplerow
    
      String text = textView.getText();
    
      if(mHighlightSet.contains(text))
       view.setTextColor(Color.RED);
      else
       view.setTextColor(Color.WHITE);
    
      return view;
     }
    

    The super’s getView will already fill in the correct word. You just want to update the styling in your getView method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.