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 6163357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:48:41+00:00 2026-05-23T21:48:41+00:00

I have a ListView backed by SimpleCursorAdapter and custom ViewBinder. I want to make

  • 0

I have a ListView backed by SimpleCursorAdapter and custom ViewBinder. I want to make items in this listview change their color on clicking. If I do that in the OnClickListener – it works paritally, changing the color of the item clicked, and of the items down the list, each 7th (I guess, the period depends on on the viewable area of the listview).

Can anyone suggest how to deal with this? Or, maybe point to a more elegant way of making items in the listView selectable?

Thank you.

UPD: (sorry for bad formatting – this is the first time I post a question):

Below is how I try to make an item in the ListView “selected”:

    private void setupListView(final ListView lv) {

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int position, final long id) {
                RelativeLayout layout = (RelativeLayout) view;
                int color;
                if (conditionMet) {
                      color = R.color.gray;
                 } else {
                      color = R.color.red;
                 }

                 for(int i = 0; i < layout.getChildCount(); i++) {
((TextView)layout.getChildAt(i)).setTextColor(getResources().getColor(color)); 
    }

                 return;
            }}

This is how I init the adapter:

        final SimpleCursorAdapter adapter =
                new SimpleCursorAdapter(
                        this,
                        itemId,
                        cursor,
                        from,
                        to
                );
        adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {

            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                final TextView textView = (TextView) view;
// do necessary conversions
                return true;
            }
        });
listView.setAdapter(adapter);
  • 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-23T21:48:42+00:00Added an answer on May 23, 2026 at 9:48 pm

    Since no other answer, and, I think, I had some troubles with the suggestion below, I post how I did it:

    1. I store ids of the items clicked in a special map

    2. in the listview onclick I check whether the id of the just clicked item is in the map: if yes, I remove it and make the item and its children color A, otherwise I add the id to the map and set the color to B

      public void onItemClick(AdapterView<?> adapterView, View view, int position, final long id) {
                  Context ctx = MainActivity.this;
                      RelativeLayout layout = (RelativeLayout) view;
                      try {
      
                              int color;
                              if (items.containsKey(id)) {
                                  items.remove(id);
                                  color = R.color.gray;
                                  tempIds.remove(id);
                              } else {
                                  items.put(id, sum);
                                  color = R.color.red;
                                  tempIds.add(id);
                              }
      
      
                          for (int i = 0; i < layout.getChildCount(); i++) {
                              final TextView textView = (TextView) layout.getChildAt(i);
                              textView.setTextColor(getResources().getColor(color));
                          }
                      } catch (ParseException e) {
                          Log.e(MainActivity.class.toString(), "Exception parsing", e);
                      }
                      return;
                  }
      

      }

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

Sidebar

Related Questions

I have a ListView that is backed by a SimpleCursorAdapter. I'd like to be
I have a ListView with a custom item layout backed by a SimpleCursorAdapter. I'd
I would have listview and a lot of items inside. I want that user
I have a listview with a DataTemplate that has a ComboBox. I want the
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
I have a ListView backed by a custom adapter based on a CursorAdapter. The
I have a ListView that gets updated frequently, at irregular intervals. I want it
I have a ListView that uses a custom adapter. The custom adapter's getView uses
I have a ListView that looks like this: Notice how the TextView is getting
I have a list of items that I wish to map onto a ListView,

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.