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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:12:51+00:00 2026-06-01T00:12:51+00:00

I have a UI that consists of a Gridview loaded with a custom adapter.

  • 0

I have a UI that consists of a Gridview loaded with a custom adapter. A ButtonAdapter, in this case. So the grid loads fine, the button clicks function like I want them to, but now I have to indicate on the button that it the “active” selection.

I thought I’d do this by just keeping track and changing the background. As it turns out, and based on a couple posts here on SO, the buttons don’t actually exist when they are off screen…and even immediately after a scroll. I’ll often get a NullPointerException when trying to change a button background after scrolling.

I’ve tried changing the views in the adapter to RadioButtons and ToggleButtons, but they all offer similar limitations.

The problem seems mostly to do with the getChildAt() that I use on the grid to “unselect” one button, or whatever, when another one is selected.

Is there a workaround for this, or perhaps another suggestion of similar functionality. A vertically scrollable, grid-like format, etc…

Thanks for the help.

EDIT:
Thanks Craigy…I did forget to put a platform on there o.0…i’ll add android.

  • 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-01T00:12:52+00:00Added an answer on June 1, 2026 at 12:12 am

    Have you considered using a Selector? In ignorance of how your buttonAdapter works or what you’re pulling it from, you can set the background drawable of any View to change according to its state using selectors.

    If your selector is defined like so (assuming the presence of appropriate drawables, of course):

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_focused="true"
              android:drawable="@drawable/list_item_pressed" />
        <item android:state_pressed="true"
              android:drawable="@drawable/list_item_pressed" />
        <item android:state_selected="true"
              android:state_activated="true"
              android:drawable="@drawable/list_item_selected" />
        <item android:state_activated="true"
              android:drawable="@drawable/list_item_selected" />
        <item android:state_selected="true"
              android:drawable="@android:color/black" />
        <item android:drawable="@android:color/transparent" />
    </selector>
    

    And then set your GridView’s choice mode to single Choice:

    <GridView
       ...
       android:choiceMode="singleChoice" />
    

    This lets the OS take care of everything for you in terms of remembering which position is selected in the list and then clearing it out for you when you’ve clicked another one

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

Sidebar

Related Questions

I have ModalPopupExtender that contains a UserControl that basically consists of a GridView and
I have a web page that consists of a checkbox (parent) and on this
I have a GridView that displays several dozen rows worth of a custom layout,
I have a database that consists of two tables, which look like this: users
I have this application that consists of two phases. Queuing phase and chatting Phase.
I have a table that consists of several Id's like this SELECT * FROM
I have a page that consists of a header div for navigation, a content
I have an application that consists of two processes (let's call them A and
I have an application that consists of two forms. One form displays data returned
Just an introduction of my code... I have a view that consists of -details

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.