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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:05:29+00:00 2026-06-10T03:05:29+00:00

I’m working on a layout that needs to display a dynamic list of items.

  • 0

I’m working on a layout that needs to display a dynamic list of items. Each item has a defined UUID, a Name(banner text), an Image URL and a boolean to indicate if it’s selected – I’ve also created a POJO to hold these. I created a custom layout to put the items in a grid view, two icons with banner text on it. It looks like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
  <RelativeLayout
    android:id="@+id/ItemLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ImageView
        android:id="@+id/ItemImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:background="@android:color/transparent" />
    <ImageView
        android:id="@+id/ItemOverlayImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:background="@android:color/transparent" />
    <TextView
        android:id="@+id/ItemTextBanner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:background="#BF000000"
        android:gravity="center"
        android:textStyle="bold" />
  </RelativeLayout>
</FrameLayout>

I’ve created the Custom Adapter and the activity as well and I’m having no issue getting all items read in, the image’s downloaded and encoded to bitmaps and the text banner being set. The problem is I want the “selected” state and image to change if the item is clicked.

I know I can add the GridView.setOnItemOnClickListener and inside I know which item as been selected as well as the parent view it comes from, but I’m not sure how to get it’s “selected” state. This link uses state from a static list in the Adapter and is what I’ve modeled after. I added the following method and called it from the GridView.setOnItemOnClickListener.

public void itemSelected(View parent, int position)
{
    if(items.get(position).isSelected())
    {
        ImageView interestSelected = (ImageView)parent.findViewById(R.id.ItemOverlayImage);
        interestSelected.setImageResource(0);
    }
    else
    {
        ImageView interestSelected = (ImageView)parent.findViewById(R.id.ItemOverlayImage);
        interestSelected.setImageResource(R.drawable.overlay);          
    }
}

The first problem is obvious, I’m not saving the state to my items array, but that is an easy fix. The real problem is only the first item is getting the overlay. So how do I alter the R.id.ItemOverlayImage for the item in the GridView selected and not just the first one? Or am I going about this totally wrong?

  • 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-10T03:05:31+00:00Added an answer on June 10, 2026 at 3:05 am

    Just some points regarding your code:

    You’re probably getting only the first item with an overlay because you search with findViewById on the parent, the GridView and not the row view view, so findViewById will return the first ImageView that it finds(which is on the first visible row). In order to show that overlay you have some options on how to do it depending on the code that you used in the adapter’s getView methodif you want to only show one item with an overlay at the time(for example, when you click one item, the previous one that was clicked(if any) will deselect) or if you have the options to toggle the item(click-> overlay, another click -> without overlay). Without knowing the information above this is how I would do it:

    public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
         ImageView overlay = (ImageView) view.findViewById(R.id.ItemOverlayImage);
         if (!items.get(position).isSelected()) { // the item doesn't have an overlay
             overlay.setImageResource(R.drawable.overlay); // set the overlay
             items.setSelected(true); // set to true so the adapter knows it
         } else { // the item has the overlay so we remove it
             overlay.setImageResource(0);
             items.setSelected(false); set to false so the adapter knows it
         }
    }
    

    So long as you use in the getView method the isSelected to set or not set the overlay you’ll be ok.

    Also you should remove the FrameLayout that wraps the RelativeLayout, as you don’t do anything with it(?!?).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.