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

  • Home
  • SEARCH
  • 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 9240685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:14:01+00:00 2026-06-18T08:14:01+00:00

I’m trying to make a ListView show multiple highlights after each item is selected,

  • 0

I’m trying to make a ListView show multiple highlights after each item is selected, but I get strange behavior from the View. If you click on the first item, it is highlighted (after clicking the OK button on the popup window). If you click on the second item however, the last item is also highlighted. Here is the log showing that the renderer.setBackgroundResource is only called the appropriate number of times.

01-30 00:54:07.957: I/HighlightActivity(343): ListView.onItemClick: selected = 0

01-30 00:54:09.757: I/HighlightActivity(343): FINISHED_WORDS[0].equals(set)

01-30 00:54:11.387: I/HighlightActivity(343): ListView.onItemClick: selected = 1

01-30 00:54:12.757: I/HighlightActivity(343): FINISHED_WORDS[0].equals(set)

01-30 00:54:12.776: I/HighlightActivity(343): FINISHED_WORDS[1].equals(set)

If you try different selection orders, all kinds of weird behavior happens. I’m not sure if this is the best way to do this, or what the problem is. (Using Android 2.3.3 API 10)

Thanks for your help,

Curchod.

Here is the Activity:

public class HighlightActivity extends ListActivity 
{
private static final String DEBUG_TAG = "HighlightActivity";
final Context context = this;
private String[] FINISHED_WORDS = {"","","","","",""};
private String[] WORDS = {"one","two","three","four","five","six"};
int selected;   
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_highlight, 
                    R.id.highlight_layout, WORDS)
    {
        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            final View renderer = super.getView(position, convertView, parent);
            if (FINISHED_WORDS[position].equals("set"))
            {
                renderer.setBackgroundResource(android.R.color.darker_gray);
                Log.i(DEBUG_TAG, "FINISHED_WORDS["+position+"].equals(set)");
            }
            return renderer;
        }
    });
    ListView list_view = getListView();
    list_view.setTextFilterEnabled(true); 
    list_view.setOnItemClickListener(new OnItemClickListener() 
    {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
          {
                selected = position;
                Log.i(DEBUG_TAG, "ListView.onItemClick: selected = "+selected);
                final String selected_word = WORDS[position];
                LayoutInflater layout_inflater = LayoutInflater.from(context);
                View popup_view = layout_inflater.inflate(R.layout.highlight_popup, null);
                final AlertDialog.Builder alert_dialog_builder = new AlertDialog.Builder(context);
                alert_dialog_builder.setView(popup_view);
                final TextView ard_player_words_popup_text = (TextView) popup_view.findViewById(R.id.highlight_popup_text);
                ard_player_words_popup_text.setText(selected_word+" selected");
                alert_dialog_builder.setCancelable(false).setPositiveButton("OK",
                        new DialogInterface.OnClickListener() 
                        {
                            public void onClick(DialogInterface dialog,int id) 
                            {
                                FINISHED_WORDS[selected] = "set";
                                dialog.cancel();
                                ListView list_view = getListView();
                                ArrayAdapter<?> adapter = (ArrayAdapter<?>) list_view.getAdapter();
                                adapter.notifyDataSetChanged();
                            }
                          }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
                          {
                              public void onClick(DialogInterface dialog,int id) 
                              {
                                  dialog.cancel();
                              }
                          });
                AlertDialog alert_dialog = alert_dialog_builder.create();
                alert_dialog.show();
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    getMenuInflater().inflate(R.menu.activity_highlight, menu);
    return true;
}

}

Here is the actrivity_highlight.xml layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/highlight_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="20sp" >
</TextView>

</RelativeLayout>

And here is the highlight_popup.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/highlight_popup_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"/>

</LinearLayout>
  • 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-06-18T08:14:02+00:00Added an answer on June 18, 2026 at 8:14 am

    It’s possible your getView method is getting a recycled convertView, with a background already set.

    Try this:

    if (FINISHED_WORDS[position].equals("set"))
    {
    renderer.setBackgroundResource(android.R.color.darker_gray);
    Log.i(DEBUG_TAG, "FINISHED_WORDS["+position+"].equals(set)");
    }
    else
    {
    renderer.setBackgroundResource(R.color.normal_background);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to make ListView using data from Array, but I need to get
I'm trying to make a ListView with 2 items in each 1 list item
I am trying to make a listview in android but i got some troubles.
I'm trying to make an Expandable ListView, but I don't know how to retrieve
I'm trying to make an application with repeatable background in a listview, but i
I'm trying to make a simple code that deletes a ListView item when the
I am trying to make URL clickable inside of ListView item. How do I
i am trying to put a button on my listView item and make a
I'm trying to make my Listview show only one record just like how DetailsView
I'm trying to display a selected item in a listview, populated with SQLite in

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.